# How do apps know the current rules for DST?

**URL:** <https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845>\
**Category:** Factual Questions\
**Created:** [April 18, 2023, 2:02pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845 "2023-04-18T14:02:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ponderoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponderoid/32/19221_2.png) [@Ponderoid](https://boards.straightdope.com/u/Ponderoid)\
**Post date:** [April 18, 2023, 2:02pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/1 "2023-04-18T14:02:01Z")

</div>

It’s straightforward, if perhaps a bit complex, to write a clock app that knows when DST is in effect for your current location. How do apps handle it when the government changes those dates?

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [April 18, 2023, 2:04pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/2 "2023-04-18T14:04:36Z")

</div>

I assume they release an updated version of the app? Even better, they just get the current time from the phone itself.

---

<div class="post-metadata">

**Author:** ![kenobi\_65](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kenobi_65/32/13178_2.png) [@kenobi\_65](https://boards.straightdope.com/u/kenobi_65)\
**Post date:** [April 18, 2023, 2:05pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/3 "2023-04-18T14:05:04Z")

</div>

The developers patch the software to account for the change in DST rules.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [April 18, 2023, 2:05pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/4 "2023-04-18T14:05:38Z")

</div>

There’s a timezone database.  
I’m not sure who maintains it, because it’s extremely complicated.  
[https://www.iana.org/time-zones](https://www.iana.org/time-zones)

---

<div class="post-metadata">

**Author:** ![gnoitall](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@gnoitall](https://boards.straightdope.com/u/gnoitall)\
**Post date:** [April 18, 2023, 2:12pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/5 "2023-04-18T14:12:20Z")

</div>

For Unix and Linux systems, a series of text (human-readable) but also computer-readable timezone definition files are installed at system setup. These are used by the operating system’s timekeeping software to make time zone adjustments to the local time computed from the monotonically advancing epoch time (a running count of rhe number of seconds that have elapsed aince midnight January 1st 1970).

These timezone files are maintained by the operating system provider and routinely patched on user systems along with everything else that gets updated periodically, so timezone rules almost always get updates before they’re needed.

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [April 18, 2023, 2:22pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/6 "2023-04-18T14:22:24Z")

</div>

Modern Unix based systems use the TZ database. It does need constant updating, as it covers all countries, timezones, and interestingly includes historical information of time shifts. So whenever a country decides to change either the date of time change or even how much, it is captured.

This has a very interesting effect. Internally time is kept in UTC. It is only when time is displayed for a user that the time is converted to whatever the time zone is set to. The time zone is simply set by the TZ environment variable. (There is a system default.) Since the TZ system knows about historical timezones, you can see the time (of say a file creation) that might be a decade ago, still correctly shown taking into account the DST setting in force at that date. Indeed the database goes back into historical times for when there are records. It is fascinating to see the UK use double daylight saving during WW2. The TZ system is independent of the Unix time epoch. You just feed it a time and date relative to UTC, and it will give you back the shifted time.

Before this came into use, Unix was utterly dumb. If you were lucky the system used UTC and there was a system wide offset to get your time zone. Early Unices only allowed the offset for UTC to be positive. Which was fine for the USA, but broken on the rest of the planet. Allowing negative offsets was one battle, allowing non integer offsets yet another.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [April 18, 2023, 2:27pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/7 "2023-04-18T14:27:08Z")

</div>

Smartphones can get the timezone when they connect to local towers. I’ve noticed that when I fly across timezones, the clock shows the origin time until a few minutes after I arrive.

---

<div class="post-metadata">

**Author:** ![Ponderoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponderoid/32/19221_2.png) [@Ponderoid](https://boards.straightdope.com/u/Ponderoid)\
**Post date:** [April 18, 2023, 2:30pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/8 "2023-04-18T14:30:21Z")

</div>

Is there a way for an app to query the database without downloading the entire thing to find out the current DST dates for a given location?

---

<div class="post-metadata">

**Author:** ![echoreply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/echoreply/32/3641_2.png) [@echoreply](https://boards.straightdope.com/u/echoreply)\
**Post date:** [April 18, 2023, 3:11pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/9 "2023-04-18T15:11:19Z")

</div>

It’s [one guy](https://onezero.medium.com/the-largely-untold-story-of-how-one-guy-in-california-keeps-the-worlds-computers-on-the-right-time-a97a5493bf73), [Paul Eggert](https://samueli.ucla.edu/time-zone-king-how-one-ucla-computer-scientist-keeps-digital-clocks-ticking/). Not a joke, it’s one guy, and a small team of volunteers maintain a database of time zones and time changes. [The database](https://www.iana.org/time-zones) is now under the auspices of the Internet Assigned Numbers Authority (IANA), but it’s still run by Eggert.

Like all good jokes, the following XKCD comic is based in far too much truth. Eggert is from Kansas, though.

> **[Dependency](https://xkcd.com/2347/)**
>
> Someday ImageMagick will finally break for good and we'll have a long period of scrambling as we try to reassemble civilization from the rubble.

Helpfully, if all you want to do is find out what time it will be in a particular place on a certain day, the [https://www.timeanddate.com/](https://www.timeanddate.com/) website is an excellent tool.

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [April 18, 2023, 3:18pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/10 "2023-04-18T15:18:47Z")

</div>

> [@gnoitall](#):
>
> These timezone files are maintained by the operating system provider and routinely patched on user systems along with everything else that gets updated periodically, so timezone rules almost always get updates before they’re needed.

All true. With emphasis on that “_almost_” at the end.

Just recently some populist know-nothing government someplace decided on a couple _day_’s notice that they would not being doing DST this year as they always had. “The people have spoken” or some such BS.

Considerable chaos ensued. I’m not sure how it resolved.

---

<div class="post-metadata">

**Author:** ![gnoitall](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@gnoitall](https://boards.straightdope.com/u/gnoitall)\
**Post date:** [April 18, 2023, 4:31pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/11 "2023-04-18T16:31:56Z")

</div>

> [@LSLGuy](#):
>
> Just recently some populist know-nothing government someplace decided on a couple _day_’s notice that they would not being doing DST this year as they always had.

I forget. Where was this?

---

<div class="post-metadata">

**Author:** ![Ponderoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponderoid/32/19221_2.png) [@Ponderoid](https://boards.straightdope.com/u/Ponderoid)\
**Post date:** [April 18, 2023, 4:37pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/12 "2023-04-18T16:37:38Z")

</div>

I’d like my app to know in advance when DST starts and ends without having to constantly be checking against some time reference. It’s already got the current U.S. system hardcoded (I don’t expect any international users) and it does the gyrations to figure out what Xth Sunday in Pentember means, but I’m trying to future-proof it. I’m running the app on a limited system that can’t handle fetching, uncompressing, and parsing an entire database, but it can do the occasional small http query to see if the rules have changed.

---

<div class="post-metadata">

**Author:** ![AlsoNamedBort](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/alsonamedbort/32/3213_2.png) [@AlsoNamedBort](https://boards.straightdope.com/u/AlsoNamedBort)\
**Post date:** [April 18, 2023, 4:46pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/13 "2023-04-18T16:46:03Z")

</div>

There are various APIs. Googling got me just a few:

> **[World Time API: Simple JSON/plain-text API to obtain the current
  time in,...](http://worldtimeapi.org/)**
>
> World Time API: Simple JSON/plain-text API to obtain the current
> time in, and related data about, a timezone.

> **[Get Started  |  Time Zone API  |  Google Developers](https://developers.google.com/maps/documentation/timezone/get-started)**
>
> A simple interface to request the time zone for a location on the earth, as well as that location's time offset from UTC.

---

<div class="post-metadata">

**Author:** ![gnoitall](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@gnoitall](https://boards.straightdope.com/u/gnoitall)\
**Post date:** [April 18, 2023, 4:46pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/14 "2023-04-18T16:46:12Z")

</div>

Here’s an example of a simple query-and-response HTTPS API provided by Google.

> **[Başla  |  Time Zone API  |  Google for Developers](https://developers.google.com/maps/documentation/timezone/get-started?hl=tr)**
>
> Dünya üzerindeki bir konumun saat diliminin yanı sıra söz konusu konumun UTC ile saat farkını istemek için basit bir arayüz.

Quoting that article:

> Request the time zone information for a specific latitude/longitude pair and date. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.

So such lookup services do exist.

(As @AlsoNamedBort mentioned.)

---

<div class="post-metadata">

**Author:** ![Ponderoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponderoid/32/19221_2.png) [@Ponderoid](https://boards.straightdope.com/u/Ponderoid)\
**Post date:** [April 18, 2023, 4:57pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/15 "2023-04-18T16:57:13Z")

</div>

Yes, I found those things when I tried to google my question first, and as far as I can tell, these things all tell me what the current DST offset is, but they don’t return the date of when the next DST change will be, do they? Or the rules for calculating those dates?

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [April 18, 2023, 5:40pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/16 "2023-04-18T17:40:36Z")

</div>

There are standard formats for determining time zone changes.  
[https://developer.ibm.com/articles/au-aix-posix/](https://developer.ibm.com/articles/au-aix-posix/)

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [April 18, 2023, 5:46pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/17 "2023-04-18T17:46:31Z")

</div>

> [@Ponderoid](#):
>
> but they don’t return the date of when the next DST change will be, do they? Or the rules for calculating those dates?

The tzinfo files contain rules from which the next time change can be computed, like “change on the last sunday of march for years between these years” but DST rules are routinely updated by national governments so and “computation” is not guaranteed to work in the future.

I don’t think it is sophisticated enough to have rules like “time changes during ramadan” listed as anything other than just a series of dates.

---

<div class="post-metadata">

**Author:** ![Digital\_is\_the\_new\_Analog](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@Digital\_is\_the\_new\_Analog](https://boards.straightdope.com/u/Digital_is_the_new_Analog)\
**Post date:** [April 19, 2023, 1:32am UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/18 "2023-04-19T01:32:30Z")

</div>

> [@Dewey\_Finn](#):
>
> Smartphones can get the timezone when they connect to local towers. I’ve noticed that when I fly across timezones, the clock shows the origin time until a few minutes after I arrive.

I’ve been out of the cell phone game for a decade, but back when I was involved, even that part was surprisingly tricky. Towers reach across time zones. Time zone lines aren’t straight.

I don’t remember all the other complications, but a friend of mine at work was responsible for a good bit of testing in this space, and used to talk about all the ways things could go wrong.

---

<div class="post-metadata">

**Author:** ![phs3](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@phs3](https://boards.straightdope.com/u/phs3)\
**Post date:** [April 19, 2023, 5:14am UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/19 "2023-04-19T05:14:54Z")

</div>

They don’t, sometimes. In 1999, Microsoft got the transition dates for Brazil wrong. I know because I was responsible for an email gateway I’d written for a large U.S. automobile manufacturer, and spent a bunch of time trying to figure out how I got it wrong. I hadn’t.

---

<div class="post-metadata">

**Author:** ![bump](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bump](https://boards.straightdope.com/u/bump)\
**Post date:** [April 19, 2023, 1:53pm UTC](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845/20 "2023-04-19T13:53:16Z")

</div>

It seems to be extremely small (~500k zipped), so I’m not sure that anyone going to all the trouble to set up some sort of service to field requests is going to really save anyone anything vs. just downloading the entire thing every now and then (you really only need it a maximum of twice a year).

[Next page](https://boards.straightdope.com/t/how-do-apps-know-the-current-rules-for-dst/982845.md?page=2)
