Difference between revisions of "Update timezone files for earlier Daylight Savings Time"

From Christoph's Personal Wiki
Jump to: navigation, search
 
 
(11 intermediate revisions by the same user not shown)
Line 4: Line 4:
  
 
*Step 1: Check that you are using the older DST definition.
 
*Step 1: Check that you are using the older DST definition.
To determine if your time zone has an issue, run this command:
+
To determine if your time zone has an issue, run this command (note that <code>zdump</code> might be located under <code>/sbin/zdump</code> or <code>/usr/sbin/zdump</code>):
  % zdump -v /etc/localtime | grep 2007
+
  $ zdump -v /etc/localtime | grep 2007
  
 
For an example, if you are living in the "Pacific" time zone, you should get something like the following:
 
For an example, if you are living in the "Pacific" time zone, you should get something like the following:
Line 17: Line 17:
 
Notice that those dates do not correspond to the second Sunday in March nor the first Sunday in November. If you see this in the output, then your DST will not start (or end) on the correct day.
 
Notice that those dates do not correspond to the second Sunday in March nor the first Sunday in November. If you see this in the output, then your DST will not start (or end) on the correct day.
  
The time zone files are using found here:
+
The time zone files are usually found here:
 
  /usr/share/zoneinfo/
 
  /usr/share/zoneinfo/
 
and they are usually linked to the <code>/etc/localtime</code>
 
and they are usually linked to the <code>/etc/localtime</code>
  % ls -lah /etc/localtime  
+
  $ ls -lah /etc/localtime  
 
   lrw-r--r--  1 root root 1.1K Jan  5  2006 /etc/localtime ->
 
   lrw-r--r--  1 root root 1.1K Jan  5  2006 /etc/localtime ->
 
   /usr/share/zoneinfo/America/Vancouver
 
   /usr/share/zoneinfo/America/Vancouver
  
*Step 2: Download the [ftp://elsie.nci.nih.gov/pub/ patch from here]. You will need the file <code>tzdata2007c.tar.gz</code> (this may have changed since writing this).
+
*Step 2: Download the [ftp://elsie.nci.nih.gov/pub/ patch from here]. You will need the file <code>tzdata2007c.tar.gz</code> (this may have changed since writing this). Then execute the following commands under the appropriate directory (they are usually located under <code>/usr/share/zoneinfo</code>):
 +
$ wget '<nowiki>ftp://elsie.nci.nih.gov/pub/tz*.tar.gz</nowiki>'
 +
$ gzip -dc tzcode*.tar.gz | tar -xf -
 +
$ gzip -dc tzdata*.tar.gz | tar -xf -
  
*Step 3: Extract the contents of the archive to a local folder.
+
*Step 3: Since, in our example, we are interested in the files related to the "Pacific" timezone, we will only need "<code>northamerica</code>" and/or "<code>pacificnew</code>". (note: Some modifications where made to the <code>europe</code> and <code>africa</code> files as well, and the last command, <code>zic backwards</code>, will complain if you do not include them.) Here are the commands to run (as root):
  
*Step 4: Since, in our example, we are interested in the files related to the "Pacific" timezone, we will only need "<code>northamerica</code>" and/or "<code>pacificnew</code>". (note: Some modifications where made to the <code>europe</code> and <code>africa</code> files as well, and the last command, <code>zic backwards</code>, will complain if you don't include them.) Here are the commands to run (as root):
+
  $ cd /path/to/tzdata2007c
 
+
  $ zic europe
  % cd /path/to/tzdata2007c
+
  $ zic africa  
  % zic europe
+
  $ zic northamerica  
  % zic africa  
+
  $ zic backwards
  % zic northamerica  
+
  % zic backwards
+
  
 
Et voilà! Now, check your results with the original command again:
 
Et voilà! Now, check your results with the original command again:
  zdump -v /etc/localtime | grep 2007
+
  $ zdump -v /etc/localtime | grep 2007
 
and you should see something like this:
 
and you should see something like this:
 
<pre>
 
<pre>
Line 46: Line 47:
 
</pre>
 
</pre>
 
It's the "Mar 11" and "Nov 4" that tell us we have successfully updated our <code>/etc/localtime</code> file.
 
It's the "Mar 11" and "Nov 4" that tell us we have successfully updated our <code>/etc/localtime</code> file.
 +
 +
==Sync localtime with rdate==
 +
Example: Create a file, e.g. <code>/etc/cron.hourly/time-sync</code>, with the following lines:
 +
#!/bin/bash
 +
/usr/bin/rdate -s time1.u.washington.edu
 +
 +
Remember to make this file executable, like so:
 +
$ chmod 775 /etc/cron.hourly/time-sync
 +
 +
==timedatectl==
 +
''Note: Most of these commands will need to be run as either root or sudo and is only valid for systems using [[systemd]].''
 +
 +
* List all available timezones on your computer/server:
 +
$ timedatectl list-timezones
 +
 +
* Set your computer's/server's timezone:
 +
$ timedatectl set-timezone region/timezone
 +
 +
* For instance, to set your timezone to United States Pacific Time (PST; -8GMT):
 +
$ timedatectl set-timezone America/Vancouver
 +
 +
Your system will be updated to use the selected timezone. You can verify with:
 +
$ timedatectl
 +
<pre>
 +
      Local time: Thu 2015-05-14 01:56:46 UTC
 +
  Universal time: Thu 2015-05-14 01:56:46 UTC
 +
        RTC time: Thu 2015-05-14 01:56:45
 +
      Time zone: Etc/UTC (UTC, +0000)
 +
    NTP enabled: yes
 +
NTP synchronized: yes
 +
RTC in local TZ: no
 +
      DST active: n/a
 +
</pre>
  
 
==References==
 
==References==
 
<references/>
 
<references/>
 
==See also==
 
==See also==
*[[zdump]]
+
*[[zdump]] &mdash; time zone dumper
*[[zic]]
+
*[[zic]] &mdash; time zone compiler
 +
 
 +
==External links==
 +
*[http://www.twinsun.com/tz/tz-link.htm Sources for Time Zone and Daylight Saving Time Data]
  
 +
__NOTOC__
 
[[Category:Linux Command Line Tools]]
 
[[Category:Linux Command Line Tools]]

Latest revision as of 01:44, 14 May 2015

Because of the Energy Policy Act of 2005, beginning in 2007, the United States will begin observing Daylight saving time (DST) from the second Sunday in March until the first Sunday in November.[1]

Older Linux kernels are using the older definition of DST and the files that control this will need to be updated. Below I will show you how to do this.

  • Step 1: Check that you are using the older DST definition.

To determine if your time zone has an issue, run this command (note that zdump might be located under /sbin/zdump or /usr/sbin/zdump):

$ zdump -v /etc/localtime | grep 2007

For an example, if you are living in the "Pacific" time zone, you should get something like the following:

/etc/localtime  Sun Apr  1 09:59:59 2007 UTC = Sun Apr  1 01:59:59 2007 PST isdst=0 gmtoff=-28800
/etc/localtime  Sun Apr  1 10:00:00 2007 UTC = Sun Apr  1 03:00:00 2007 PDT isdst=1 gmtoff=-25200
/etc/localtime  Sun Oct 28 08:59:59 2007 UTC = Sun Oct 28 01:59:59 2007 PDT isdst=1 gmtoff=-25200
/etc/localtime  Sun Oct 28 09:00:00 2007 UTC = Sun Oct 28 01:00:00 2007 PST isdst=0 gmtoff=-28800

Notice that those dates do not correspond to the second Sunday in March nor the first Sunday in November. If you see this in the output, then your DST will not start (or end) on the correct day.

The time zone files are usually found here:

/usr/share/zoneinfo/

and they are usually linked to the /etc/localtime

$ ls -lah /etc/localtime 
  lrw-r--r--  1 root root 1.1K Jan  5  2006 /etc/localtime ->
  /usr/share/zoneinfo/America/Vancouver
  • Step 2: Download the patch from here. You will need the file tzdata2007c.tar.gz (this may have changed since writing this). Then execute the following commands under the appropriate directory (they are usually located under /usr/share/zoneinfo):
$ wget 'ftp://elsie.nci.nih.gov/pub/tz*.tar.gz'
$ gzip -dc tzcode*.tar.gz | tar -xf -
$ gzip -dc tzdata*.tar.gz | tar -xf -
  • Step 3: Since, in our example, we are interested in the files related to the "Pacific" timezone, we will only need "northamerica" and/or "pacificnew". (note: Some modifications where made to the europe and africa files as well, and the last command, zic backwards, will complain if you do not include them.) Here are the commands to run (as root):
$ cd /path/to/tzdata2007c
$ zic europe
$ zic africa 
$ zic northamerica 
$ zic backwards

Et voilà! Now, check your results with the original command again:

$ zdump -v /etc/localtime | grep 2007

and you should see something like this:

/etc/localtime  Sun Mar 11 09:59:59 2007 UTC = Sun Mar 11 01:59:59 2007 PST isdst=0 gmtoff=-28800
/etc/localtime  Sun Mar 11 10:00:00 2007 UTC = Sun Mar 11 03:00:00 2007 PDT isdst=1 gmtoff=-25200
/etc/localtime  Sun Nov  4 08:59:59 2007 UTC = Sun Nov  4 01:59:59 2007 PDT isdst=1 gmtoff=-25200
/etc/localtime  Sun Nov  4 09:00:00 2007 UTC = Sun Nov  4 01:00:00 2007 PST isdst=0 gmtoff=-28800

It's the "Mar 11" and "Nov 4" that tell us we have successfully updated our /etc/localtime file.

Sync localtime with rdate

Example: Create a file, e.g. /etc/cron.hourly/time-sync, with the following lines:

#!/bin/bash
/usr/bin/rdate -s time1.u.washington.edu

Remember to make this file executable, like so:

$ chmod 775 /etc/cron.hourly/time-sync

timedatectl

Note: Most of these commands will need to be run as either root or sudo and is only valid for systems using systemd.

  • List all available timezones on your computer/server:
$ timedatectl list-timezones
  • Set your computer's/server's timezone:
$ timedatectl set-timezone region/timezone
  • For instance, to set your timezone to United States Pacific Time (PST; -8GMT):
$ timedatectl set-timezone America/Vancouver

Your system will be updated to use the selected timezone. You can verify with:

$ timedatectl
      Local time: Thu 2015-05-14 01:56:46 UTC
  Universal time: Thu 2015-05-14 01:56:46 UTC
        RTC time: Thu 2015-05-14 01:56:45
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

References

  1. wikipedia:Daylight saving time

See also

  • zdump — time zone dumper
  • zic — time zone compiler

External links