Dates times and timezones

This document explains how dates, times and timezones are handled in Totara.


Which timezone to use?

All dates are stored in database as UTC unix timestamps. Most dates are entered and displayed in the current user's timezone.
There are a few exceptions where different timezones are used:

  • Server scheduling uses server timezone
  • Server related admin settings should use server timezone
  • Date/time data being imported should use the server timezone
  • Notifications such as emails sent by the server should be using timezone of the target user
  • Some special areas record and display an extra timezone - this helps to coordinate user meetings.


Entering dates

Use the date/time forms element. There is a new option 'showtimeozne' that allows user to enter time in any other timezone.

External date data can be parsed using

totara_date_parse_from_format()

with $servertimezone = true.


Storing dates

Dates are always stored as UTC timestamps.

In the database they are stored in integer columns, with a length of 10 where applicable.


Displaying dates and times

Always use

userdate()

, you ask

core_date::get_server_timezone()

or

core_date::get_user_timezone($user)

to get other timezones.


Exporting dates

Use the server timezone and the import date format from admin settings.


Date calculations

Use new PHP DateTime logic. The timezone parameter can be obtained from

core_date::get_server_timezone_object()

or

core_date::get_user_timezone_object()

Supported timezones

Totara supports the following timezones:

World timezones are our preferred format and allow for daylight saving modifications to be applied automatically.


Legacy PHP date functions

If you need to use old PHP date functions you have to set the default timezone first using

date_default_timezone_set()

and afterwards reset it back using

core_date::set_default_server_timezone()

Known problems

  • Windows cannot handle dates outside of 32 bit integer range.
  • totara_date_parse_from_format()

    does not support explicit timezone in date formats

  • calendar block and page might not work properly especially around DST switching
  • userdate()

    does not support displaying of timezones - we need some way to display server timezone dates