Why is the daylight saving time cutover time 1 millisecond too soon in some time zones?

Raymond Chen

If you dig into the Windows time zone database, you’ll see that some time zones list the moment when the time zone transitions into or out of daylight saving time as 23:59:59.999 instead of midnight. Why a millisecond too soon?

My colleague Matt Johnson spends a lot of time working with time zones and explains many of the strange and wacky artifacts of time zones in this StackOverflow answer.

In it, I learned these fascinating facts:

  • If the official time zone change occurs at midnight, Windows intentionally misreports the change as occurring at 23:59:59.999 to work around code which “incorrectly used <= instead of < to evaluate the transition”, which means that they would unwittingly bounce the date back and forth, resulting in much havoc.
  • Governments will from time to time announce time zone changes on very short notice,¹ leaving computer programmers scrambling to get the time zone data updated in time, or applying workarounds (like “Use this other time zone for now”) until the real fix can be deployed.
  • I was aware that Brazil and Israel change their time zone rules every year, but I wasn’t aware that Morocco changes its clocks four times a year, and this Antarctic research station changes its clocks three times a year.

Read Matt’s StackOverflow answer for all the juicy details. Note in particular his conclusion:

That all said, if you are able to avoid using Windows time zone data in your application, I recommend doing so. Prefer IANA data sources, or those derived from them. There are many routes to working with IANA time zone data. Newer Windows APIs like Windows.Globalization.Calendar and Windows.Globalization.Date­Time­Formatting.Date­Time­Formatter in WinRT/UWP do indeed use IANA time zones, and that is clearly the path forward. In the standard C++ space, I highly recommend using Howard Hinnant’s date/tz libraries, or those provided by the ICU project. There are several other viable choices as well.

If you want to keep your finger on the pulse of Microsoft’s responses to time zone changes around the world, you should check out the Daylight Saving Time and Time Zone Hot Topics page and the Microsoft Daylight Saving Time and Time Zone Blog.

Bonus reading: How Microsofts ‘Time Lords’ Keep the Clocks Ticking.

Bonus watching: How to Have the Best Dates Ever! by Matt Johnson.

¹ In one notable case, a government announced a change to the date the country would change to daylight saving time, and then less than two weeks before the change was scheduled to take effect, the legislature passed a law abolishing daylight saving time outright, upon which the legislature and the government got into a shouting match over who was right, and then confusing the matter even further, another government representative mentioned a third cutover date, later reaffirmed by the state news agency, and then four days before the third cutover date, the state news agency announced that the change passed by the legislature is the one that would be implemented after all. Temporary workaround: Disable daylight saving time adjustments until the time zone information can be updated.


Discussion is closed.

Feedback usabilla icon