## Features & Development

### pretty-printing dates in a header

by Dick Lane -
Number of replies: 6
The attached header file produces hardcopy with first line of the form
Lenny Oiler    brief title of assignment    Math 001, Spring 2012
and subsequent line (first of screen display)
Solve these problems while studying section 2.5 (Sum Things) before class on Tuesday, January 31.

That header has only three lines which need changing for use in a subsequent term:
$TermYear = 'Spring 2012' ;$DATE = 'January 31' ;  ## or 'Jan 31'
$DAY = 'Tuesday' ; ## or 'Tue' I would like to reduce or eliminate the need for such periodic revision. (Note: end of the attached example uses$formattedDueDate which displays "01/31/2012 at 09:00am MST".)

Once upon a time, I could set the first variable with a command of the form
$PG_environment{'TermYear'} = 'Spring 2008' ; in the course's webworkCourse.ph file. I tried something similar with course.conf (the apparent replacement for webworkCourse.ph), e.g.,$envir{'TermYear'} = 'Spring 2012' ;
but without success.

I'm now considering adapting some ideas from
http://www.perlhowto.com/working_with_date_time
to generate all three variables as functions of $dueDate, functions which my headers could load from a file in the course's macros directory. Before I do that, I wonder whether there might already be suitable tools in webwork2/lib/WeBWorK/Utils.pm (or macros already in the WeBWorK system). Suggestions for further reading will also be welcomed. In reply to Dick Lane ### Re: pretty-printing dates in a header by Arnold Pizer - Hi Dick, It's easy to do what you used to do with WeBWorK 1 ("$PG_environment{'TermYear'} = 'Spring 2008' ").  Use the same technique as in http://webwork.maa.org/wiki/TextbookSpecificMessages

Can you think of a better way to make this option more visible?  E.g. did you look at problem techniques and if so, what did you look for?

I'm not sure if you are satisfied with $formattedDueDate or not. If not, I don't know what you are looking for. Arnie In reply to Arnold Pizer ### Re: pretty-printing dates in a header by Danny Glin - On the topic of$formattedDueDate, there are a couple of things that I would like to see changed if possible:
1. Spell out the month (i.e. January 31, 2012 instead of 01/31/2012).  In the past the mm/dd/yyyy format used in WeBWorK has caused some confusion around here, as in Canada dd/mm/yyyy is commonly used.
2. Add the day of the week (i.e. Wednesday) to the display, as students are more likely to relate to an assignment being due Wednesday night rather than it being due on a specific date.
Of course the more involved solution would be to set this up so that each of the day, month, year and hopefully day of the week variables are available individually as well, so that individuals can customize how they want dates to look.

Danny

### Re: pretty-printing dates in a header

by Jason Aubrey -
Hi Danny,

This is something that needs to be made more flexible, not only for the case of Canadian users, but also for the potential for increasing number of users outside of the US as a result of the localization effort.

Since the dates/times are stored in the database as unix epoch time stamps, it probably wouldn't be too hard to change the date handing routines in Utils.pm to format the date based on a parameter set in global.conf. The perl DateTime module can already do this, and is what is used in webwork for date handing.

Jason

### Re: pretty-printing dates in a header

by Arnold Pizer -
Hi,

We will also need the reverse parsing operation to parse the formatted date/time. We currently use the home grown parseDateTime in Utils.pm but hopefully there is a CPAN module that would meet our needs (maybe DateTime::Format::ISO8601).

Arnie

### Re: pretty-printing dates in a header

by Danny Glin -
I consider the reverse parsing less of a priority since it is on the professor side.  I've never seen problems with that since in all our use cases (and I think almost all instances in WeBWorK), when a professor is entering a date, they are only editing data in a pre-filled form field, so they never have to try to type it from scratch.

Perhaps rather than expand the reverse parser, it would be more effective to build (or obtain) a UI for entering dates.  I'm thinking of the ubiquitous clickable calendars used for entering dates on the web.

Danny
$pg{specialPGEnvironmentVars}{TermYear} = 'Spring 2012' ; and a header file can display its text by (text line) \{ protect_underbar($courseName) \}, $TermYear I did not find discussion of header files in either the Problem Techniques or Subject Area collections, also found nothing sufficiently specific in http://webwork.maa.org/wiki/Configuration I do use$formattedDueDate in its current form and my header files may soon toggle between
... will close $formattedDueDate and ... was closed ... by using something of the form$closeTense = (time > $main::dueDate ? 'was closed' : 'will close' ); On the other hand, Danny's second point is important to me (and Jason mentions why Danny's first point is broadly relevant). Citing day-of-week in text form is easier for students to process than a numerical reference (which remains useful to avoid ambiguity). Danny's suggestion about providing system variables (or functions) would let an instructor choose their preferred way to present that info. I suspect Jason is correct that Utils.pm is the place to do this work, but I suggest it be done with new functions rather than making fundamental changes to existing ones. Possible new names:$dueDay, $dueMonth (e.g., January),$dueMo (e.g., Jan); perhaps $dueDayLong for Wednesday but$dueDayShort for Wed.