I am hoping to make this question and the answers to it the definitive guide to dealing with daylight saving time, in particular for dealing with the actual change overs.
If you have anything to add, please do
Many systems are dependent on keeping accurate time, the problem is with changes to time due to daylight savings - moving the clock forward or backwards.
For instance, one has business rules in an order taking system that depend on the time of the order - if the clock changes, the rules might not be as clear. How should the time of the order be persisted? There are of course an endless number of scenarios - this one is simply an illustrative one.
As important, if not more so:
I would be interested in programming, OS, data persistence and other pertinent aspects of the issue.
General answers are great, but I would also like to see details especially if they are only available on one platform.
Do:
datetimeoffset
type that can store both in a single field.1970-01-01T00:00:00Z
(excluding leap seconds). If you require higher precision, use milliseconds instead. This value should always be based on UTC, without any time zone adjustment.DateTimeOffset
is often a better choice than DateTime
.DateTime
, and DateTimeZone
classes. Be careful when using DateTimeZone::listAbbreviations()
- see answer. To keep PHP with up to date Olson data, install periodically the timezonedb PECL package; see answer.>=
, <
).Don't:
America/New_York
with a "time zone offset", such as -05:00
. They are two different things. See the timezone tag wiki.Date
object to perform date and time calculations in older web browsers, as ECMAScript 5.1 and lower has a design flaw that may use daylight saving time incorrectly. (This was fixed in ECMAScript 6 / 2015).Testing:
Reference:
timezone
tag wiki page on Stack Overflowdst
timezone
Other: