How Debian cron handles DST transitions
blog.healthchecks.io
blog.healthchecks.io
So for example I live in Europe/Oslo, which is UTC+02 when DST is in effect (CEST). When DST is not in effect, my time zone becomes UTC+01 (CET).
And therefore, when we adjust our clocks, time is not really moved.
Although it may seem like the time turns back from 3 AM to 2 AM on 31 October 2021 in my location, that’s only true if you don’t take the time zone into account.
What actually happens is we go from:
2021-10-31T02:59:59.999…+0200
to:
2021-10-31T02:00:00.000…+0100
And we see then that if we convert this time to UTC, we have simply a transition from:
2021-10-31T00:59:59.999…Z
to:
2021-10-31T01:00:00.000…Z
So actually, nothing bad happened.
The article also says as much, but I wanted to comment on how I think about it when I consider DST, because I think it’s a pretty straight forward way to look at it.
The same is true for say PST and PDT.
I don't know if you can type things like "CST" into Debian, but I don't think you can.
It's not though, it means "Central Standard Time", which is UTC-06:00. It is sometimes sloppily misused to mean "Central Time", which is a sloppy term, meaning either UTC-06:00 (CST) or UTC-05:00 (CDT) depending on the time of year and where you are in the country.
> or America/Indiana/Indianapolis (for the weird one that doesn't use DST)
1. You mean `America/Indiana/Knox` or `America/Indiana/Tell_City` or historically almost any of the other `America/Indiana/…` zoneinfo files except for Indianapolis. Indianapolis has "always" (since 1961) been "Eastern" rather than "Central", it's other non-Indianapolis regions of Indiana that have been "Central, but without DST".
2. But regardless, it's outdated; all of Indiana has been doing DST since 2006; mostly Eastern (EDT/EST), but a few western parts of the state are Central (CDT/CST).
> (While researching this comment, I found that Indiana has at least 8 different time zones, so ... good luck with that.)
They only still exist for pre-2007 dates; for post-2007 dates they're all equivalent to either America/Chicago (…/Knox and …/Tell_City) or America/New_York (the other 6 of them).
> I don't know if you can type things like "CST" into Debian, but I don't think you can.
It's inconsistent. You can type in EST or MST, but not CST.
This is kind of the weakness with the IANA time zone classification. This defines time zones as the set of clocks that have shared the same time since 1970, so every time an Indiana county decided it wanted to move from Eastern to Central or vice versa, it got split into its own timezone. It reflects a level of precision that is perhaps greater than Indianans themselves actually keep.
[Also, FWIW, Indiana does observe DST now.]
(That's if you go by length of coast. If you go by population of states that do use DST, then, okay. If you go by number of states with a coast on the eastern side of the country that use DST, that's only 2/3, or 3/4 if you include Tasmania.)
The Europe/Oslo identifier from the time zone databases was meant for context, but may have made what I tried to say less clear, sorry about that.
I want a cronjob set up to change the “closed” sigh to say “open”.
How do I set that with UTC?
if utc_now().to_timzone(my_timezone) >= "9AM":
sign = "open"
I know you didn't mean this, but it was a problem I thought about: How does one make sure the local clock tower actually changes in cadence with DST? You can't, so I guess you could use open vz with a camera to have your open sign be based on what time is actually seen on the tower.I know it's just an example, but I say in jest, don't use cron jobs to change your closed sign to open! If you can't make it to your shop, people will be waiting around all day for you to unlock the door. Very unhappy customers.
The second advantage is that you can check in multiple timezones especially if the server itself is in DST. Does cron itself let you set the timezone for each individual check? Or does it only run in one timezone? As far as I can tell, it only lets you use one timezone.
For something important, I would look at it completely differently by testing it:
- What happens if I have a scheduled cronjob running every day at a certain time, but I want to override it for one specific day and have that job run later? (e.g. how is it accomplished so that I can maintain the default behavior while overriding and opening later on specific days)
- How can I make different commands run in different timezones? (as it stands now I find conflicting information about this)
- What happens if my machine lost power when the job needed to run? (it looks like it just never runs the script)
- Can I input a specific time and test if cron will set open for that specific time? (this doesn't seem possible)
and historically there have been even weirder cases
If youre just gonna run it every hour, you might as well while(1){ check time; do stuff; sleep 1 hour;} now there's one less dependency?
For instance, Nepal uses UTC+05:45, and the time shifted by 15 minutes in 1986 (from UTC+05:30): https://www.timeanddate.com/time/zone/nepal/kathmandu
That said, I think running every 15 minutes handles all currently-observed time zones.
At one company I remember helping build a scheduling UI for a linear TV broadcast channel, where you plan out the broadcast day in 24h blocks. Worked great except twice a year when, due to DST, you have either a 23h day or a 25h day, and half a dozen ways various customers expected that to be handled. The de facto solution was to have happy customers 363 days a year. :-/
Hey, but thank goodness for https://en.wikipedia.org/wiki/Uniform_Time_Act or it would have been even worse!
The reason is that things that happened in the past will have a specific moment on the arrow of time at which they happened, and UTC is as good as anything else for putting a consistent label on the arrow of time.
But, for things that are going to happen in the future, you have no way of knowing if two "time labels" that right now point to the same moment on the arrow of time might have some change that causes them to point to different moments. In this case UTC removes the ambiguity about the timezone that the time is in, but it adds ambiguity about which moment in time you're really talking about.
Let's say you want to schedule something for 9pm local time (UTC-3). So you schedule it for midnight UTC. Then your timezone shifts to UTC-2 and your appointment moves to 10pm. That's likely not at all what you intended. It's also why you need to pick a "master" timezone when you're sending invites to multiple timezones and let the rest of the times be derived from the "single source of truth" time.
You still need to use your brain and careful UI design. Things that a user scheduled to happen at a specific local time need to store the relevant timezone, implicitly or explicitly.
Google's NTP servers smear leap seconds over an entire day, so UTC may appear continuous despite leap seconds.
I guess this can cause quite a bit of weirdness if you use a spec like "5,17,32,47 * * * *" (to avoid the "thundering herd" of cronjobs at xx:00) and then getting four concurrent instances running at 02:00 in the daylight switchover hour?
Edit: I just ran the second example – https://gist.github.com/cuu508/7e42e5eecd42babf43f8d0dd0d987...
I'm pretty sure the article is wrong, too, because it implies that a DST transition won't cause cron jobs to be skipped or run twice. But it looks like the logic in Better-timeskip-handling.patch doesn't account for the possibility that the computer might be rebooted near a DST transition. Reboot immediately after the time falls back and it'll happily run the cron job a second time. The right way to handle this would have been to internally convert the crontab entries to UTC before scheduling them. It's surprising that OpenBSD (the origin of this patch) blundered this - usually they get the details right.
This definition of Unix clock is only mostly correct, due to its treatment of leap seconds, but the way they are treated in Unix clock is not like how they are treated in UTC anyway (some Unix seconds last 2 SI seconds), so in this sense, Unix clock is not UTC either.
The slight disconcertingness of the hour changes is worth it.
Yeah, it makes it harder for programmers to accommodate. I'll play my violin for them next July when it's nice and bright outside at 7:30pm. :)