Daylight saving time and Linux
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.