Questions tagged [dst]

DST is the tag for Daylight Saving Time issues. DST, also known as summer time, starts when a time zone shifts its clocks forward (in the spring), and ends when the clocks shift back (in the fall).

DST is the tag for Daylight Saving Time issues. Daylight Saving Time is the period when a time zone shifts its time forward in the spring (usually by one hour) and then shifts back in the fall. This creates many programming issues dealing with the lost hour in the spring, and the extra hour in the fall.

Daylight saving time is sometimes called "Summer Time", as time is changed during the summer as compared to the rest of the year. Keep in mind that the northern and southern hemispheres observe summer at different times.

Also, sometimes the term is erroneously called "daylight savings time", or just "daylight savings". Neither term is correct. There is no "s". Another erroneous term is "Day Light Savings" (or "DLS"), which is incorrect because "daylight" is a single word. All of these terms should be avoided.

To illustrate the effects of DST, consider the following graphs. These represent the daylight saving time transitions for the US Pacific time zone.

                Spring Forward DST Transition

                Fall Back DST Transition

While other time zones may transition at different points in time, the behaviors are similar. There is a "gap" of missing local time during the "spring forward" transition, and there is an "overlap" of ambiguous local time during the "fall back" transition.

These graphs also demonstrate the mathematical behaviors of the transitions:

  • Conversion from UTC to Local Time is a function over the range of all time that the local time zone was in existence.

    • However, it may not be a continuous function, due to the transitional adjustments that are made for daylight saving time.

    • Keep in mind that the local time zone was probably not always well defined, or it may have been defined using some earlier calendar system.

  • Conversion from Local Time to UTC is not a pure function because:

    • There may be a discontinuity for the "spring forward" transition, so a local time in this range would be undefined.

    • There may be a range where it is not a function at all, because there is more than one possible outcome for a single input, which occures during the "fall-back" transition.

    • This can lead to problems because some people think that you can always convert in either direction, which is false for any time zone that observes daylight saving time.

Also keep in mind that in the Northern Hemisphere, the "spring forward" transition occurs early in the year and the "fall back" transition occurs late in the year. However, in the Southern Hemisphere the seasons are inverted, so the "fall back" transition typically comes early in the year, while the "spring forward" transition comes late in the year.

Also keep in mind:

  • Not every time zone of the world uses daylight saving time. In fact, the majority do not. See this Wikipedia Article for details.

  • Of those that uses it, each time zone decides how DST applies. Different countries will start and end daylight time at different dates.

  • Not every time zone transitions by one hour. For example, the Australia/Lord_Howe time zone only shifts by 30 minutes.

  • Governments of the world often make changes to how they want to follow DST. You cannot assume that the current rules have always applied in the past or always will apply in the future.

  • DST transition days will have less or more actual time than 24 hours. In most cases, spring-forward days will have 23 hours, and fall-back days will have 25.

  • There are not always exactly a single pair of DST transitions in a given year. Other real-world cases include:

    • One spring transition : This occurs when a time zone decides to stay on "permanent summer time". For example, in 2015 the Turks and Caicos Islands sprung forward in March and stayed there. This is often modeled as a change in base-offset from UTC-5 to UTC-4.

    • One fall transition : This occurs when a time zone that was on "permanent summer time" switches back to standard time. This occurred across Russia in 2014.

    • Two transitions : This is the common case.

    • Three transitions : This is much rarer, but occurred in 2011 in Samoa. The first two transitions were for DST, and the third occurred when 24 hours were skipped to change the island's base-offset from UTC-10 to UTC+14.

    • Four transitions : This occurs when a country that observes DST decides to suspend it temporarily. This has been done in both Egypt and Morocco for the observation of Ramadan.

1319 questions
10
votes
1 answer

UTC to local time conversion for previously saved datetimes if rules for timezone change

I'm storing a product in db. All dates (sql server datetime) are UTC and along with the dates I store the time zone id for that product. User enters the dates when product is available "from" and "until" in the listing. So I do something like: //…
findev
  • 258
  • 1
  • 6
10
votes
1 answer

How to detect Ambiguous and Invalid DateTime in PHP?

When dealing with local DateTime values provided by a user, it's quite possible to have a time that is either invalid or ambiguous, due to Daylight Saving Time transitions. In other languages and frameworks, there are often methods such as…
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
9
votes
5 answers

DateTime difference operator considers daylight saving?

As far as I know the difference operator of the DateTime type considers leap years: so new DateTime(2008, 3, 1) - new DateTime(2008, 2, 1) // should return 29 days new DateTime(2009, 3, 1) - new DateTime(2009, 2, 1) // should return 28 days But…
Michael Damatov
  • 15,253
  • 10
  • 46
  • 71
9
votes
3 answers

MySQL: DATE_SUB/DATE_ADD that accounts for DST?

This returns 1 (aka TRUE) SELECT DATE_SUB(NOW(), INTERVAL 24*100 HOUR) = DATE_SUB(NOW(), INTERVAL 100 DAY); 100 days ago, the hour of day does not change. But due to Daylight Savings Time (US), 100 twenty-four hour periods ago is actually one hour…
700 Software
  • 85,281
  • 83
  • 234
  • 341
9
votes
4 answers

Ways to deal with Daylight Savings time with Quartz Cron Trigger

I have a quartz cron trigger that looks like so:
Jon Bristow
  • 1,675
  • 3
  • 27
  • 42
9
votes
1 answer

How do java.time API determines zone rules changes by the government?

I don't live in a country using DST. I save a future LocalDateTime, Offset from UTC and ZoneId in DB Government of that zone changes DST rules That future time comes, I will retrieve the LocalDateTime in that zone If I apply ZoneId and Offset to…
letthefireflieslive
  • 11,493
  • 11
  • 37
  • 61
9
votes
2 answers

Find out timezone offset

I wish to find the timezone offset using Lua, however I'm facing what looks odd behaviour, so I must be missing something. I'm using the code: local t1 = os.time(); local t2 = os.time( os.date( "!*t" ) ); print( t1, t2, t1 - t2 ); local t1 =…
Javier Mr
  • 2,130
  • 4
  • 31
  • 39
9
votes
2 answers

Get actual DST savings in milliseconds

I'm making analog clock in Java Swing. To calculate clock pointer angles I need: UTC time in milliseconds which I can get with System.currentTimeMillis() TimeZone offset TimeZone DST savings. For 2) and 3) I thought of using…
zlatanmomic
  • 93
  • 1
  • 1
  • 4
9
votes
3 answers

Get Time in London

How can I get the current local wall clock time (in number of millis since 1 Jan 1970) in London? Since my application can run on a server in any location, I think I need to use a TimeZone of "Europe/London". I also need to take Daylight Savings…
dogbane
  • 266,786
  • 75
  • 396
  • 414
9
votes
3 answers

How to detect change of system time in Linux?

Is there a way to get notified when there is update to the system time from a time-server or due to DST change? I am after an API/system call or equivalent. It is part of my effort to optimise generating a value for something similar to SQL NOW() to…
ϹοδεMεδιϲ
  • 2,790
  • 3
  • 33
  • 54
9
votes
2 answers

PHP Daylight savings conundrum

I have a general question about dealing with daylight saving time. I guess its not really PHP specific, but I am writing in PHP, so I figure it wouldn't hurt to include it. I have a calendar app built using jquery fullcalendar. The user views…
train
  • 610
  • 2
  • 11
  • 20
9
votes
1 answer

How to detect an ambiguous DST overlap in Joda Time?

In Joda Time, one can easily use the DateTimeZone.isLocalDateTimeGap method to tell if a local date and time is invalid because it falls into the gap created by a spring-forward daylight saving time transition. DateTimeZone zone =…
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
9
votes
1 answer

NSDateFormatter returns nil for the 2 AM hour

I'm trying to convert a string to an NSDate using the following code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; [dateFormatter…
8
votes
3 answers

does php's date_default_timezone_set adjust to daylight saving?

Does php's date_default_timezone_set adjust to daylight saving? I have this code, and wonder if it will always result in the correct Stockholm time? date_default_timezone_set('Europe/Stockholm'); $timestamp = date("Y-m-d H:i:s");
Robin Manoli
  • 2,162
  • 2
  • 25
  • 30
8
votes
2 answers

Python - From DST-adjusted local time to UTC

A specific bank has branches in all major cities in the world. They all open at 10:00 AM local time. If within a timezone that uses DST, then of course the local opening time also follows the DST-adjusted time. So how do I go from the local time to…
Erik Ninn-Hansen
  • 565
  • 2
  • 7
  • 16