Slashdot Mirror


Daylight Savings and UNIX?

Anonymous asks: "My company recently asked me to write them a report on how UNIX properly handles the switch to Daylight Savings Time, and back again. When our systems administrators received the report, I was somewhat surprised. Many of them weren't aware that 'cron' would run the affected jobs twice in the fall, and not at all in the spring. Apparently, the man pages on some operating systems, like Solaris, aren't forthcoming with details. Others groups, like database administrators, are completely unaware of the differences between epoch time and wall clock time. Are even technical users ignorant on how UNIX handles time, time zones, and time conversion?"

25 of 94 comments (clear)

  1. Wrong by gus+goose · · Score: 5, Insightful
    This is taken from the HP Cron man page.
    Spring and Autumn Time Transitions
    On the days of daylight savings (summer) time transition (in time zones and countries where daylight savings time applies), cron schedules commands differently from normal. In the following description, an ambiguous time refers to an hour and minute that occurs twice in the same day because of a daylight savings time transition (usually on a day during the Autumn season). A nonexistent time refers to an hour and minute that does not occur because of a daylight savings time transition (usually on a day during the Spring season). DST-shift refers to the offset that is applied to standard time to result in daylight savings time. This is normally one hour, but can be any combination of hours and minutes up to 23 hours and 59 minutes (see tztab(4)). When a command is specified to run at an ambiguous time, the command is executed only once at the first occurrence of the ambiguous time. When a command is specified to run at a nonexistent time, the command is executed after the specified time by an amount of time equal to the DST-shift. When such an adjustment would conflict with another time specified to run the command, the command is run only once rather than running the command twice at the same time. Commands that are scheduled to run during all hours (there is a * is in the hour field of the crontab entry) are scheduled without any adjustment.
    This is taken from the Linux cron manpage though:
    Note that this means that non-existant times, such as "missing hours" during daylight savings conversion, will never match, causing jobs scheduled during the "missing times" not to be run. Similarly, times that occur more than once (again, during daylight savings conversion) will cause matching jobs to be run twice.
    So, if you want things to work, use HP-Unix.

    gus

    P.S. Get to it, linux guys ... maybe I will have a look.

    --
    .. if only.
    1. Re:Wrong by JimR · · Score: 5, Informative

      Hmmm... this is what man cron gives on my Debian Linux box...

      Special considerations exist when the clock is changed by less than 3
      hours, for example at the beginning and end of daylight savings time.
      If the time has moved forwards, those jobs which would have run in the
      time that was skipped will be run soon after the change. Conversely,
      if the time has moved backwards by less than 3 hours, those jobs that
      fall into the repeated time will not be re-run.

      Only jobs that run at a particular time (not specified as @hourly, nor
      with '*' in the hour or minute specifier) are affected. Jobs which are
      specified with wildcards are run based on the new time immediately.

      Clock changes of more than 3 hours are considered to be corrections to
      the clock, and the new time is used immediately.
      --
      #exclude <ms/windows.h>
    2. Re:Wrong by Col.+Klink+(retired) · · Score: 4, Funny
      From my Debian Woody cron man page:
      Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Conversely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run.
      --

      -- Don't Tase me, bro!

    3. Re:Wrong by mvdwege · · Score: 4, Interesting

      I can corroborate the previous statements.

      Although I am on Debian like the first two posters to reply, I did some more checking, and Debian installs vixie cron. AFAIK this is what most Linux distros install by default, including Red Hat, which I runned before this.

      Would you mind telling us what distro you had to dig up to find this gem? They deserve to be rightly flamed (and by extension if you can't give a satisfactory answer, you deserve to be flamed).

      Mart
      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
  2. Nope by Clue4All · · Score: 5, Insightful

    Are even technical users ignorant on how UNIX handles time, time zones, and time conversion?

    Nope, technical users know that UNIX systems should be run using GMT, which doesn't observe daylight savings time.

    --

    Is your browser retarded?
    1. Re:Nope by Covener · · Score: 5, Insightful

      Technical users know UNIX systems should keep their hardware clocks in UTC, but should obviously be aware of timezones and local time.

  3. Varies depending on which "cron" by shoppa · · Score: 5, Informative
    There are multiple cron-type systems out there.

    Many Linux distributions ship with a heavily (and I mean heavily) patched up version of Vixie-cron as the default cron package. This is what many people refer to in this thread when they say "Linux cron".

    There are other cron packages out there for Linux; for example, fcron. Section 2.2 of the fcron FAQ says:

    First, you must understand that fcron determines, for each job, its next time and date of execution. It then determines which of those jobs would be the next to run and then, sleeps until that job should be run. In other words, fcron doesn't wake up like Vixie cron each minute to check all job in case one should be run ... and it avoids some problems associated with clock adjusts.

    This means that if the new time value is set into the past, fcron won't run a particular job again. For instance, suppose the real time and system clock are 3:00, so the next job cannot be scheduled to run before 3:00, as it would have already been run and re-scheduled.

    First, suppose you set your system clock into the past, say to 2:00, Presuming that the last run was shortly before 3:00. then fcron will sleep until the next job should be executed. The execution time for a job is determined by identifying the last time that the job ran and computing the next scheduled time. This means that the next scheduled time must be on or after 3:01. Therefore, in this example, fcron will not run a job for at least one hour.

    Next, if you set the system time into the future, say to 4:00, fcron will run every job scheduled between the old and the new time value once, regardless of how many times it would have been scheduled. When fcron wakes up to run a job after the time value has changed, it runs all the jobs which should have run during the interval because they are scheduled to run in a past time.

    As special case is when "@xxx" style scheduling rules are involved, you must consider the "adjustment-interval". The "adjustment-interval" is the time difference between the original system time and the new system time. If the ... run at "adjust-interval" too early or too late depending of the nature of the adjust.

    To conclude, fcron behaves quite well for small clock adjusts. Each job which should have run does so once, but not exactly at the correct time as if the job were scheduled within the adjustment interval. But, if you have to make a big change in the time and date, you should probably reset all the scheduled "nextexe" by running "fcrontab -z" on all the fcrontabs.

    And to further complicate matters, most commercial Unix-type OS's are either completely independent of Vixie-cron or they genetically "diverged" from Vixie-cron so long ago that they bear only faint resemblance to the original.

    Maybe those technical people who you are questioning worked on a non-Linux system that doesn't suffer from the idiosyncrancies of Vixie-cron, or maybe they use fcron.

  4. I guess that's what you get.... by eclectric · · Score: 3, Funny

    for using daylight saving time. Come to Indiana, where people are more normal, and don't try to change time itself.

    1. Re:I guess that's what you get.... by RocketJeff · · Score: 3, Funny
      Come to Indiana, where people are more normal, and don't try to change time itself.
      I always heard that (most of) Indiana didn't change the clocks because they thought it would confuse the cows...
    2. Re:I guess that's what you get.... by rw2 · · Score: 3, Informative

      confuse the cows

      Smirk. My uncle works in state government in Indiana and I tease him about this from time to time. He's been around long enough to remember the debate on this one and he says that *one* of the reasons that they don't switch is because the drive-in-movie theaters had a strong lobby the last time this was seriously discussed.

      That always cracks me up. The entire state is out of step with their neighbors because of theater owners.

      They are considering changing to a more conventional (notice I didn't say 'normal', just conventional) system and he says "I don't think that lobby is as strong as it used to be".

    3. Re:I guess that's what you get.... by crath · · Score: 4, Insightful

      It's sad to hear that Indiana may bow to peer pressure from the rest of the world w.r.t. Daylight Savings Time (DST). There have been a number of very credible studies done over the past decade, and DST costs lives (and money) due to the manner in which it disrupts our body clock.

      The grand hypocracy of the whole DST gambit is the DST supporters' claim that the energy savings justify DST; i.e., let's annually sacrifice a few thousand people to save a bit of energy.

      If DST supporters truly want to put an open and honest argument on the table for their position, their cost-benefit analysis needs to account for the lost lives, lost quality of life due to personal injuries, lost productivity, lost monies, etc., in addition to tallying up the energy savings and extra time spent on the golf course.

      Why is it too much to expect that people turn their brains on, fire a few neurons, and produce cogent thought? DST is yet another example of, "It *feels* good so it must the right thing to do."

    4. Re:I guess that's what you get.... by crath · · Score: 3, Informative
      A couple of links:
      Accident rates increase in response to DST---Stanley Coren of the University of British Columbia
      UK government's Transport Research Laboratory numbers---the practice of turning the clocks back had led to 3,000 deaths on Britain's roads in the last 30 years

      Lastly, my feel good comment was in relation to the extra hours spent on the golf course. It was a bit of a flame and I probaby should have deleted that comment before posting.

  5. In FreeBSD... by cperciva · · Score: 5, Interesting

    In FreeBSD, the default times for daily/weekly/monthly cron jobs are chosen so that they don't fall within the daylight savings time mess.

    1. Re:In FreeBSD... by mosch · · Score: 3

      Also, in FreeBSD you get a choice of whether to handle changes in GMT offset in an intelligent way or not. -o gives the old behaviour, -s makes it smart.

  6. Time zones by sql*kitten · · Score: 3, Informative

    Are even technical users ignorant on how UNIX handles time, time zones, and time conversion?

    Maybe this has been fixed by now (AFAIK as of SunOS 5.8 it hasn't) but Unix' handling of timezones has always been pretty lame. For example, if you want to change timezone in your shell (and for processes subsequently spawned) you just set the TZ environment variable. If you want to change the system time globally, su to root and use the date command, and running processes will see it next time they ask the OS for the time. OK so far. But if you want to change the timezone globally, for running processes, you can't because time zone comes from init - at the very least you have to stop and restart processes after setting TZ, and if you're going to do that, you might as well edit /etc/default/init and reboot!

  7. Daylight Savings? Blech by Eponymous,+Showered · · Score: 4, Funny

    Just have your company relocate to Indiana. We don't need no steenking daylight savings.

  8. Re:date -s by duffbeer703 · · Score: 3, Insightful

    The world already has a standard -- UTC.

    System time should be set to UTC, and the time display should be seperate configuration step.

    Using NTP should take care of the leap second problem, as long as your Stratum-1 server is accurate.

    --
    Conformity is the jailer of freedom and enemy of growth. -JFK
  9. Grammar Nazi Time by zsazsa · · Score: 4, Informative

    Okay, this has to be the absolutey most assinine thing I've done on Slashdot, but I've gotta do it.

    It's daylight saving time, not daylight savings time. NIST says so.

    Anyway, if it were up to me, we wouldn't have daylight saving at all.

  10. Dual boot? by Gerry+Gleason · · Score: 3, Interesting
    Of course, this is the right solution, and it is probably universal for UNIX vendors (Sun, HP, IBM, ...), but when your running on PC hardware there are extra considerations.

    Linux gives you a choice about how to keep the hardware clock (Local or UTC), and the system clock is UTC with an offset setting for local time. If you're single boot with Linux, a UTC hardware clock is probably best, but if you ever want to boot into Windows, your going to have to adjust somehow.

    Having the hardware clock in local time creates a problem when the time change happens, but you don't see it until you reboot. Someone incorrectly said you need to update from the hardware clock, but it is just the opposite, you have to update the hardware clock from the system clock after the time change. Since the system knows both when the change happens and whether the hardware clock is in local or UTC, it could take care of this little detail. It would be a nice touch for the distribution makers to handle this is some way. This is one of those things that doesn't really live in a single program/module but relates to interactions, so the distribution maker probably should own it. Of course, it would be nice if the hardware clock knew what the current offset is, then the issue would be easily and correctly solved.

    BTW, I've always wondered about how the transition day is calculated. I've never been able to find a simple description of it. Most (all?) systems seem to know when it is, and it allways seems to be correct (for US timezones excluding Indiana), but I can't see how it could be 'calculated' from a simple rule that doesn't need to be updated from time to time. The TZ variable indicates whether the zone has DST and what the offset change is, but it doesn't have any information about when the change is. Is it just a 'last Sunday in October/April' or something like that hard coded in the library?

    1. Re:Dual boot? by lewiscr · · Score: 3, Informative
      BTW, I've always wondered about how the transition day is calculated. I've never been able to find a simple description of it.
      *snip*
      Is it just a 'last Sunday in October/April' or something like that hard coded in the library?

      Depends on the Country and the Hemisphere. The US (and most of North America) is first sunday in April and last sunday in Octoboer. I didn't realize that the Southern Hemisphere observers DST the other six months (ie, their summer). Seems obvious in hindsight.

      Web Exhibits has history and start/stop days by country.

      I shamelessly stole a bit of DST calculation code from their web site.

  11. Re:The Y2030 "Bug" by pne · · Score: 3, Informative

    2038 is more like it. 03:14:07 UTC on 19 January 2038, to be exact.

    And no, just hoping everyone's going to be running 64-bit systems by then is not going to help if you have, for example, file formats which only allocate 4 bytes to storing a time_t value.

    I'll not have reached retirement age in 2038... I wonder how many C programmers will be called out of their holes to patch programs similar to the hunt for COBOL experts at the end of last century.

    --
    Esli epei etot cumprenan, shris soa Sfaha.
  12. Re:=P abcd1233243459834982 by einstein · · Score: 3, Funny

    You reboot?

    *rimshot*
    --

  13. UTC by mirabilos · · Score: 3, Interesting

    Servers ought to use /usr/share/zoneinfo/right/UTC
    anyways because of the logs and stuff, and me, being
    consistent, despite living in right/Europe/Berlin zone,
    switched all my clocks (server, desktop, notebook,
    watch, wrist clock, microwave oven clock, car clock
    etc.) to UTC. I just add the one or two hours in mind.

    --
    My Karma isn't excellent, damn it! (And /. still does not get UTF-8 right in 2012. Wow.)
  14. Windoze by linuxwrangler · · Score: 3, Funny
    All this reminds me of the guy doing a writeup on the then-new Windows 95 years ago. He was apparently trying to get his article in on deadline when it became time to "fall back". He wrote that he was impressed by the fact that Windows told him that the time had changed back and asked if he wanted the computer's clock reset.

    He answered "yes" but became rather less impressed an hour later when, once again, it asked him if the clock should be reset. For fun he kept answering yes each hour till he was done with his article.

    Database, cron and other timezone problems aside, at least a properly set up *nix always knows what time it is both locally and in UTC so the other programs at least have a shot at running properly.

    --

    ~~~~~~~
    "You are not remembered for doing what is expected of you." - Atul Chitnis
  15. Re:NTP by BlueUnderwear · · Score: 4, Informative
    Why is this drivel moderated at 4?

    First, NTP does not affect spring/fall time "changes" at all. Regardless of whether you have NTP or not, this "change" happens correctly. Indeed, daylight saving time only affects how time is displayed (or broken up in day, hour, minute, second), and does not affect the physical clock at all (which is kept in UTC at all times). NTP however, ensures accuracy by synching the physical clock (kept in UTC) to a master.

    Moreover, the subject of this discussion is not the accuracy of the displayed time, but rather how cron (which works in local time) copes with with "duplicate" and "missing" hours. Installing NTP does nothing to help this, only picking the right cron works. Or just use the commonsense solution of not scheduling any important jobs between 2am and 3am.

    --
    Say no to software patents.