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
32
votes
3 answers

Converting Between Local Times and GMT/UTC in C/C++

What's the best way to convert datetimes between local time and UTC in C/C++? By "datetime", I mean some time representation that contains date and time-of-day. I'll be happy with time_t, struct tm, or any other representation that makes it…
Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
30
votes
6 answers

PHP UTC to Local Time

Server Environment Redhat Enterprise Linux PHP 5.3.5 Problem Let's say I have a UTC date and time such as 2011-04-27 02:45 and I want to convert it to my local time, which is America/New_York. Three questions: 1.) My code below might solve the…
John
  • 303
  • 1
  • 3
  • 4
28
votes
2 answers

Use Python to find out if a timezone currently in daylight savings time

We have a server that runs on GMT time. I need to write a Python script that determines if it's currently (at this very second) Daylight Savings Time (DST) in Los Angeles, CA. How can I accomplish this? I took a look at pytz and time, but I can't…
Joey Mason
  • 707
  • 1
  • 8
  • 15
28
votes
1 answer

Convert a unixtime to a datetime object and back again (pair of time conversion functions that are inverses)

I'm trying to write a pair of functions, dt and ut, that convert back and forth between normal unix time (seconds since 1970-01-01 00:00:00 UTC) and a Python datetime object. If dt and ut were proper inverses then this code would print the same…
dreeves
  • 26,430
  • 45
  • 154
  • 229
27
votes
2 answers

Oracle date compare broken because of DST

We've been debugging an issue with a SQL query executed from an app server running Java via Hibernate. The error: [3/10/14 10:52:07:143 EDT] 0000a984 JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 1878, SQLState:…
Chris Williams
  • 11,647
  • 15
  • 60
  • 97
27
votes
2 answers

timezone with DST handling by PHP

I am working on a calendar application. In this users from different time-zones create/view events. I am thinking to follow below method to save event time in UTC and display them in user's local time. Note: user has their preferred timezone…
Krishna Shetty
  • 1,361
  • 4
  • 18
  • 39
25
votes
2 answers

How do I write unit tests to make sure my date/time based code works for all time zones and with/out DST?

I'm using JodaTime 2.1 and I'm looking for a pattern to unit test code which performs date/time operations to make sure it behaves well for all time zones and independent of DST. Specifically: How can I mock the system clock (so I don't have to…
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
24
votes
9 answers

Calculating daylight saving time from only date

I am working with an Arduino and a real time clock chip. The chip compensates for leap years and such, so it will always have the correct date, but it does not handle daylight saving time, I assume due to regional complications. The clock can give…
Muggz
  • 243
  • 1
  • 2
  • 5
23
votes
2 answers

Are Windows timezone written in registry reliable?

I'm creating a c++ project that should works on several timezone. The application receives an event, with a reference timezone, and this event is shown graphically to the user at the correct hour, in his local timezone. For example, an user working…
Jean-Milost Reymond
  • 1,833
  • 1
  • 15
  • 36
23
votes
4 answers

Daylight savings time in Python

I am writing a program which deals a lot with timezones and crossing them. The two things I deal with most are creating a datetime object from "now" and then localizing a naive datetime object. To create a datetime object from now in the pacific…
jmetz
  • 815
  • 1
  • 9
  • 19
22
votes
3 answers

Working with timezones and daylight savings time in Javascript

My single-page javascript app retrieves data in JSON format via REST calls. Dates come formatted using the UTC timezone in standard ISO8601 format, such as 2011-02-04T19:31:09Z. When signing up for the service, users select their timezone from a…
Tauren
  • 26,795
  • 42
  • 131
  • 167
22
votes
5 answers

How to add one day to a time obtained from time()

I have a time represented as the number of seconds elapsed since midnight, January 1, 1970, UTC (the results of an earlier call to time()). How do I add one day to this time? Adding 24 * 60 * 60 works in most cases, but fails if the daylight saving…
Andrew Stein
  • 12,880
  • 5
  • 35
  • 43
22
votes
1 answer

Python: How to convert a timezone aware timestamp to UTC without knowing if DST is in effect

I am trying to convert a naive timestamp that is always in Pacific time to UTC time. In the code below, I'm able to specify that this timestamp I have is in Pacific time, but it doesn't seem to know that it should be an offset of -7 hours from UTC…
user1152532
  • 697
  • 3
  • 7
  • 15
20
votes
8 answers

Get Timezone Information in VBA (Excel)

I would like to determine a time offset to GMT/UTC (including daylight saving time) for different countries at a specific date in VBA. Any ideas? EDIT (from self-answer): Thank you 0xA3. I quickly read-over the linked page. I assume that you can…
Marcel Menz
  • 1,075
  • 7
  • 17
  • 25
20
votes
5 answers

How to create Daylight Savings time Start and End function in SQL Server

I need to create a function in SQL server that returns daylight savings time start datetime and daylight savings time end datetime. I've come across a few examples on the web, however they all are using the 1st date of March and the 1st date of…
Amanda Brine
  • 311
  • 2
  • 4
  • 13
1
2
3
87 88