gordon.dewis.ca - Random musings from Gordon

Subscribe

Daylight saving time and Linux

March 08, 2007 @ 00:58 By: gordon Category: Current affairs

The US Energy Policy Act of 2005 included a section that amended the Uniform Time Act to have daylight saving time start in March rather than April, effective 11 March 2007. Ignoring the fact that it probably will not result in any significant energy savings, in my opinion, it poses some technical challenges for people and companies who have computers. (I’ll write about the energy savings aspect later!)

Though I’ve been running Linux for more than 15 years, I have never given much thought to how the operating system handles timezones. It was all rather blackboxish and just worked. The change in daylight saving time means that it’s suddenly not going to work properly. Fortunately, an article in eWeek addressing this issue caught my eye today. It referenced a Linux-Watch article that had very good instructions for Linux sysadmins.

In a nutshell, Linux (and most other *NIX operating systems) uses a set of files, located in /usr/share/zoneinfo on most systems, that define timezones in excrutiating detail from days of old to the end of the current epoch in 2038. These files are compiled using a tool called zic from text files that have the rules in them. Diehards will probably modify these files by hand to reflect the change for 2007, while the rest of us will go to ftp://elsie.nci.nih.gov/pub/ to download the most recent files.

Before downloading anything, however, you want to check to see if your system is perhaps already aware of the change.

The file /etc/localtime typically holds the timezone information. My old 2.2.34 Slackware system had this as a symbolic link pointing to /usr/share/zoneinfo/Canada/Eastern (because I live in Ottawa), while my Fedora Core 2 system had a copy of the Eastern file in /etc/localtime. Presumably the Fedora system copied the file from /usr/share/zoneinfo/Canada/Eastern as part of the installation process.

To see what’s in the file and determine whether you need to make a change, use the zdump command.

[root@seedling tzdata]# zdump -v /etc/localtime |grep 2007
/etc/localtime Sun Apr 1 06:59:59 2007 UTC = Sun Apr 1 01:59:59 2007 EST isdst=0 gmtoff=-18000
/etc/localtime Sun Apr 1 07:00:00 2007 UTC = Sun Apr 1 03:00:00 2007 EDT isdst=1 gmtoff=-14400
/etc/localtime Sun Oct 28 05:59:59 2007 UTC = Sun Oct 28 01:59:59 2007 EDT isdst=1 gmtoff=-14400
/etc/localtime Sun Oct 28 06:00:00 2007 UTC = Sun Oct 28 01:00:00 2007 EST isdst=0 gmtoff=-18000

As you can see, my daylight saving time was set to start at 07:00:00 UTC on April 1st this year. As daylight saving time kicks in on March 11th, this means I need to modify the file.

I then went to ftp://elsie.nci.nih.gov/pub/ and downloaded tzdata2007c.tar.gz and put it in /root/tzdata (you’ll need to create that directory first). Once there, I untar’d it.

Using the zic command, I compiled the new timezone files that applied to me thusly:

[root@seedling tzdata]# zic -d zoneinfo northamerica

This created a zoneinfo directory in my /root/tzdata directory containing compiled versions of the rules. I moved these into /usr/share/zoneinfo using the following command:

[root@seedling tzdata]# cp -vr –reply=yes * /usr/share/zoneinfo

NB: you may not need the –reply=yes depending on your shell settings. seedling is used primarily as my Asterisk server and DHCP server so I don’t spend much time on it and thus haven’t made non-interative my default for cp.

Because seedling, my Fedora Core 2 system, had a static file rather than a symbolic link, I replaced the file with a symbolic link to /usr/share/zoneinfo/Canada/Eastern file. This makes it easier to manage and means that if daylight saving time is switched back to April that I won’t have to worry about forgetting to update /etc/localtime.

[root@seedling tzdata]# mv localtime localtime.ORIG;ln -s /usr/share/zoneinfo/Canada/Eastern localtime

Backups of crucial files are always important, and you can see that I saved the original file just in case it’s needed.

You can confirm that the new daylight saving time start and end dates have taken effect using the zdump command:

[root@seedling etc]# zdump -v /etc/localtime|grep 2007
/etc/localtime Sun Mar 11 06:59:59 2007 UTC = Sun Mar 11 01:59:59 2007 EST isdst=0 gmtoff=-18000
/etc/localtime Sun Mar 11 07:00:00 2007 UTC = Sun Mar 11 03:00:00 2007 EDT isdst=1 gmtoff=-14400
/etc/localtime Sun Nov 4 05:59:59 2007 UTC = Sun Nov 4 01:59:59 2007 EDT isdst=1 gmtoff=-14400
/etc/localtime Sun Nov 4 06:00:00 2007 UTC = Sun Nov 4 01:00:00 2007 EST isdst=0 gmtoff=-18000

As you can see, the dates now reflect March rather than April. If you remove the grep, you’ll see the dates from days of old to the end of the epoch in 2038.

Obviously, if you’re following these instructions and you don’t live in Canada’s Eastern timezone, you’ll want to select a more appropriate file.

4 Responses to “Daylight saving time and Linux”


  1. Elie says:

    THANKS. It WORKES LIKE A CHARM!

  2. gordon says:

    Glad you found it helpful! 🙂

  3. John says:

    Thanks Gordon.
    14 machines updated no problems.

  4. gordon says:

    It appears that the nih.gov server is no longer available. For tzdata files, try http://www.iana.org/time-zones


Trackbacks/Pingbacks

  1. gordon.dewis.ca | Daylight Saving Time (March 08, 2008 @ 11:12)
  2. gordon.dewis.ca | Falling back in time (November 05, 2010 @ 14:45)
  3. gordon.dewis.ca | Falling forward through time (March 12, 2011 @ 08:36)
  4. gordon.dewis.ca | It’s time to fall back (November 06, 2011 @ 00:55)
  5. gordon.dewis.ca | Brace yourself for a little sleep deprivation (December 17, 2011 @ 10:59)
  6. gordon.dewis.ca | Warning: Impending sleep deprivation and increased accident rates (March 10, 2012 @ 20:38)
  7. gordon.dewis.ca | Warning: Setting clocks back will result in increased accidents and messed up sleep patterns (November 03, 2012 @ 22:33)
  8. gordon.dewis.ca | Springing forward: Lose some sleep, increase your risk of a heart attack (March 08, 2014 @ 23:07)
  9. gordon.dewis.ca | Falling backwards (November 10, 2015 @ 13:13)
  10. gordon.dewis.ca | Spring forward, lose some sleep (March 12, 2016 @ 22:20)
  11. gordon.dewis.ca | Brace yourself: we’re changing the clocks again (November 05, 2016 @ 10:20)

Leave a Reply