Skip Navigation

Toolset Date Field stores local time in the database instead of UTC

Won't fix

Reported for: Toolset Types 1.0

Topic Tags: Types plugin

Symptoms

Toolset date fields store the date in UNIX timestamp format (the number of seconds since 1 Jan 1970).

But that’s not quite accurate, because we don’t first convert the local time to UTC before generating the timestamp (and all timestamps should be UTC by definition).

The correct way to store dates in this way would be:

– a local date/time is created (e.g. selected in a form)
– this is converted to UTC
– a timestamp is generated from this UTC date/time
– the timestamp is stored in the database

Then when displaying the date/time:

– the timestamp is retrieved from the database
– the timestamp is converted to a UTC date/time
– this date/time is converted to local time for display

But since the date field was first created (many years ago) we have simply converted the local date/time to a “timestamp” without first converting it to UTC. When displaying the field it is converted from the “timestamp” directly to the local date/time without any conversion required.

As long as you are creating the date/time field and displaying the date/time field with Toolset then this does not present any problems.

But, if you use custom code or 3rd-party APIs to work with these stored “timestamps” you will need to allow for the fact that they are not stored in UTC (as they should be) and are stored in the local timezone when they were created.

Because of the large number of existing sites already using the date field it was decided not to change the implementation.

Workaround

Leave
a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>