Algumas vezes você precisa mudar o arquivo timezone para se adequar as regras/leis regionais, como em:

Histórico: O Debian inclui arquivos timezone na árvore de diretório /usr/share/zoneinfo, que é fornecida pelo pacote tzdata para o Etch e posteriores. (Para o Sarge e anteriores os arquivos são parte do libc6). Esses pacotes podem ser atualizados periodicamente:

Para fazer uma mudança antes da mudança feita pelo projeto Debian, siga este processo:

Mais detalhes podem ser encontrados abaixo, usando Sydney Australia como exemplo. Substitua o nome do fuso horário e o nome do arquivo pela sua região.

Verificar Fuso Horário Configurado

Para verificar ou mudar o fuso horário para o qual seu sistema Debian está configurado,

# dpkg-reconfigure tzdata

O que isso faz? Isso muda o /etc/localtime. O detalhes da mudança segue:

Nas versões do Debian Etch e posteriores, o /etc/localtime é uma cópia do arquivo de dados original. Verifique o conteúdo de /etc/timezone para ver o nome do fuso horário. Se o sistema estiver configurado normalmente, você deverá descobrir que o arquivo zoneinfo referenciado por este nome é idêntico ao /etc/localtime. Por exemplo, você pode verificar isso executando:

$ diff -s /etc/localtime /usr/share/zoneinfo/`cat /etc/timezone`
Files /etc/localtime and /usr/share/zoneinfo/America/New_York are identical

O comando tzconfig atualiza tanto o /etc/localtime quanto o /etc/timezone.

Nas versões Sarge e anteriores, o /etc/localtime é um link para um arquivo. Verifique para onde o /etc/localtime linka:

# ls -l /etc/localtime
lrwxrwxrwx    1 root     root           48 Mar 31 11:19 /etc/localtime -> /usr/share/zoneinfo/Australia/Sydney

Verifique Se Necessário

O programa zdump copia a tabela de fuso horário. Use-o para verificar as datas da mudança de horário de verão. Por exemplo, este sistema tem regras australianas antigas, mostrando uma mudança do horário de verão em 26 de março:

# zdump -c 2007 -v Australia/Sydney|grep 2006
Australia/Sydney  Sat Mar 25 15:59:59 2006 UTC = Sun Mar 26 02:59:59 2006 EST isdst=1 gmtoff=39600
Australia/Sydney  Sat Mar 25 16:00:00 2006 UTC = Sun Mar 26 02:00:00 2006 EST isdst=0 gmtoff=36000
Australia/Sydney  Sat Oct 28 15:59:59 2006 UTC = Sun Oct 29 01:59:59 2006 EST isdst=0 gmtoff=36000
Australia/Sydney  Sat Oct 28 16:00:00 2006 UTC = Sun Oct 29 03:00:00 2006 EST isdst=1 gmtoff=39600

Obter o Arquivo de Fuso Horário

Obtenha uma cópia do arquivo de fuso horário "australasia" ou específico do país de um pacote tzdata recente ou do site upstream.

Para obter o arquivo australasia das origens tzdata, configure seu sources.list com linhas deb-src para sua versão de distribuição atual, busque a fonte, descompacte-a e edite o arquivo. Por exemplo, em um sistema Debian Lenny (números de versão podem variar):

# mkdir /tmp/tzdata
# cd /tmp/tzdata
# apt-get install dpkg-dev
# apt-get source tzdata
# cd tzdata-2008e
# tar xfz tzdata2008e.tar.gz
# more australasia

Para contornar o Debian e pegar os arquivos de onde o projeto Debian os tirou:

% mkdir /tmp/tzdata
% cd /tmp/tzdata
% wget 'ftp://elsie.nci.nih.gov/pub/tzdata*.tar.gz'
% tar xfz tzdata*.tar.gz
% more australasia

Agora você deve ter todos os arquivos de fuso horário.

Se você estiver usando o arquivo do pacote de origem sem a alteração, altere o arquivo adicionando as novas linhas. Por exemplo, estas linhas estão no arquivo corrigido para a mudança do início de 2006 em australasia:

...
Rule    AN      2001    max     -       Oct     lastSun 2:00s   1:00    -
Rule    AN      2006    only    -       Apr     Sun>=1  2:00s   0       -
Rule    AN      2007    max     -       Mar     lastSun 2:00s   0       -
...

Pretest Change

This is an optional step. It tests the source file without changing the system configuration. It can be done as an ordinary user.

$ mkdir test-tz
$ /usr/sbin/zic -d test-tz australasia
$ TZ=`pwd`/test-tz/Australia/Sydney date --date="2006-04-01 16:00:10 UTC"
Sun Apr  2 02:00:10 EST 2006

This test works by compiling the timezone source file into a directory, then asking the date command to test translating a UTC time into localtime near the expected discontinuity.

Commit Change

The zic program changes the timezone table. Give it the name of the australasia or country-specific source file you changed. For example:

# /usr/sbin/zic australasia

Then reconfigure the tzdata package, which will update /etc/localtime:

# dpkg-reconfigure tzdata

Verification Test 1: Dump Timezone Rules

Use the zdump program again to confirm the change. For example this system has the change properly applied, showing a change from daylight saving on 2nd April:

# zdump -c 2007 -v Australia/Sydney|grep 2006
Australia/Sydney  Sat Apr  1 15:59:59 2006 UTC = Sun Apr  2 02:59:59 2006 EST isdst=1 gmtoff=39600
Australia/Sydney  Sat Apr  1 16:00:00 2006 UTC = Sun Apr  2 02:00:00 2006 EST isdst=0 gmtoff=36000
Australia/Sydney  Sat Oct 28 15:59:59 2006 UTC = Sun Oct 29 01:59:59 2006 EST isdst=0 gmtoff=36000
Australia/Sydney  Sat Oct 28 16:00:00 2006 UTC = Sun Oct 29 03:00:00 2006 EST isdst=1 gmtoff=39600

Verification Test 2: Translate a UTC Time

You can use the --date option to the date command see how the system will interpret a particular time. This method does not change the system clock.

$ date --date="2006-04-01 15:59:50 utc"
Sun Apr  2 02:59:50 EST 2006
$ date --date="2006-04-01 16:00:10 utc"
Sun Apr  2 02:00:10 EST 2006

Verification Test 3: Observe Rollover

It is possible to change your system's time so as to demonstrate the fix is good. There are side-effects of changing the time, such as distortion of file dates, or interoperability problems with other systems nearby, so it's only a good idea on a test system.

To do the test, use the date --utc command to change the time to just before the first discontinuity identified by zdump, then use the date command to show the local time, over the discontinuity. For example:

# date --utc 040115592006.50 ; date ; sleep 20 ; date
Sun Apr  2 02:59:50 EST 2006
Sun Apr  2 02:00:10 EST 2006

Test Failure Scenarios

Restarting Daemons and Long-Running Programs

After the zoneinfo files are updated, you may need to restart daemons and other long-running programs to get them to use the new zone information. Examples of such programs include apache, bind, cron, fetchmail -d, inetd, mailman, sendmail, and sysklogd. A common symptom of this problem is seeing incorrect timestamps mixed in with the correct timestamps in your log files (e.g. /var/log/syslog). Even interactive programs like "mutt" may continue to use the old timezone information until they are restarted.

Binary Portability

The compiled zoneinfo file appears to be platform and architecture independent, so if you have multiple machines to update you should be able to move the file as-is without running zic again. Similarly, you can just pull updated zoneinfo files from a machine running a different Debian release, or even download the latest tzdata package from unstable, extract the zoneinfo files from within the .deb file, and install them into the /usr/share/zoneinfo directory tree.

References