Dates, Times, and Time Zones

From WeBWorK_wiki
Jump to navigation Jump to search

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.

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 which 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 entered 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 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 you favorite time zone to their module.