Dates, Times, and Time Zones

From WeBWorK
Jump to: navigation, search

Contents

General Information

WeBWorK uses the Olson database (http://en.wikipedia.org/wiki/Zoneinfo) for time zone information. To see a list of valid time zones connect to http://search.cpan.org/dist/DateTime-TimeZone/

These time zones are more refined than standard time zone usage in that they include switches to daylight savings time (e.g. some parts of a time zone may make the switch and others may not). For example if you are in the eastern US, on the list you will see DateTime::TimeZone::America::New_York and you should use America/New_York when entering time zone information into WeBWorK.

A default time zone for the WeBWorK system is set in the file /opt/webwork/webwork2/conf/global.conf In that file, e.g. replace $siteDefaults{timezone} = ""; by $siteDefaults{timezone} = "America/New_York";

To set a different time zone for a particular course, go to Course Configuration and enter your desired time zone under the General tag.

There is a subtle difference in how date/times are entered into WeBWorK and how they are displayed but almost no one will notice this difference. In the Hmwk Sets Editor you will see date/times displayed as 11/14/2009 at 07:45am EST. You can always enter date/times in the format 11/14/2009 at 07:45am without the time zone information and WeBWorK will use the same time zone the course uses. You can usually enter dates/times in the format WeBWorK uses to display them, e.g. 11/14/2009 at 07:45am EST with the time zone information. However, for a few places in the world, this will cause an error.

Date Time Display

As of WeBWorK 2.5.1, it is possible to customize the format of the date/time shown to students, including localization to a country/language combination available on your system (i.e. automatically translate day and month names). This is done by setting the following variables:

  • $studentDateDisplayFormat (set in conf/localOverrides.conf for the whole server, or course.conf for a specific course). This variable should be set if you wish to change the way open/due/answer dates are displayed to students. The available date components can be found at http://search.cpan.org/~drolsky/DateTime-0.76/lib/DateTime.pm#strftime_Patterns. For example, if one entered the following:
$studentDateDisplayFormat="%a %b %d at %l:%M%P";

One would see something like the following on the student problem sets page:

now open, due Wed Jul 18 at 12:00am

By default, perl will use the en_US locale for things like names of days and months. To override this, use the following variable.

  • $siteDefaults{locale} (set in conf/site.conf for the whole server, or course.conf for a specific course). This variable defaults to en_US, so it only needs to be set if you wish to use day/month names in a different language. The allowed values depend on which locales are installed on the server. This can be determined using the locale command. To determine the locale that is in use in the operating system, simply type locale. To get a list of installed locales, type locale -a
    • For example, if you wish dates to use the French Canadian localization, you would enter the following in either site.conf or course.conf:
$siteDefaults{locale}=fr_CA.utf8;

Note: the $siteDefaults{locale} variable currently only applies to dates displayed to students, and the variables used for dates and times in set definition files. For now (July 2012), dates displayed to instructors will always be as described earlier on this page.

Using Dates in Header Files

Most of the available components of the open, due and answer dates are made available as PG variables for use in Header Files. For a list of these variables, see Header File Variables.

Possible Errors

As we said above you can usually enter date/times in the format WeBWorK uses to display them, e.g. 11/14/2009 at 07:45am EST with the time zone information. But not always. For example if you are in Israel, you would use Asia/Jerusalem as your time zone and WeBWorK will display date/times in the format 10/24/2012 at 08:17am IST. However if you enter a date/time in this format, you will get the error message

Error messages
   Time zone 'IDT' not recognized.

Entering the date/time in the format 10/24/2012 at 08:17am works fine and is usually what you want to do. WeBWorK uses whatever time zone the course is set up to use so in this case WeBWorK displays 10/24/2012 at 08:17am IST. You can also enter date/times using the format 10/24/2012 at 08:17am Asia/Jerusalem which gives the same result. You can use other time zones, e.g. 10/24/2012 at 08:17am America/New_York but in this case WeBWorK displays 10/24/2012 at 02:17pm IST as it should.

If you are interested in what is really going on, continue reading.

Detailed Information

WeBWorK uses standard Perl modules to convert back and forth from a human readable format into epoch time (which is in seconds from 1/1/1970).

The main Perl module used is

http://search.cpan.org/~drolsky/DateTime-TimeZone-1.01/lib/DateTime/TimeZone.pm

This uses time zones like "Asia/Jerusalem" but also has short names such as IST for display. Here's what is said about these short names:

$tz->short_name_for_datetime( $dt )

Given a DateTime object, this method returns the "short name" for the current observance and rule this datetime is in. 
These are names like "EST","GMT", etc.

It is strongly recommended that you do not rely on these names for anything other than display. These names are not official, 
and many of them are simply the invention of the Olson database maintainers. Moreover, these names are not unique. 
For example, there is an "EST" at both -0500 and +1000/+1100.

So these short names are for display only. That is why "IDT" produces an error but "Asia/Jerusalem" does not.

However since the display uses the short names, e.g. EST, most people will use these when entering date/times and WeBWorK uses a second routine that usually works but not always.

If someone enters EST the first routine fails since EST (and IDT, etc.) are not valid. But since everyone probably does this (instead of using America/New_York), that is they just copy what the display looks like, WeBWorK calls a second module Zone.pm (see http://search.cpan.org/~gbarr/TimeDate-1.19/lib/Time/Zone.pm) which knows quite a few short names but certainly not all - click on the above link and view the source to see the ones it does know. E.g. it does not know IDT or IST and this is the reason for the above errors.

The best thing to do is to enter times without using short names (IST, IDT, etc.) and then date/times will be in whatever timezone the course uses.

If you really want to be able to use a few specific short names such as IST or IDT, you could edit the Zone.pm file on your local server. On many systems you will find it at /usr/share/perl5/Time/Zone.pm. However this will be hard to maintain. Another possibility is to contact the authors (Graham Barr <gbarr@pobox.com> David Muir Sharnoff <muir@idiom.com> Paul Foley <paul@ascent.com>) and ask them if they will add your favorite time zone to their module.

follow us