2

I recently noticed the following (strange) behavior:

user@pc:~$ date
  Mi 21. Jun 12:03:10 CEST 2017
user@pc:~$ date +%Z
  CEST
user@pc:~$ export TZ=`date +%Z`
user@pc:~$ date
  Mi 21. Jun 10:03:30 CEST 2017
user@pc:~$ date +%Z
  CEST

Thus, after setting the TZ environment variable to the current system time zone, the clock is 2 hours delayed. It looks like UTC (CEST-2hours is UTC). If I now set TZ to other values, the clock remains unchanged:

user@pc:~$ export TZ=UTC
user@pc:~$ date
 Mi 21. Jun 10:07:09 UTC 2017
user@pc:~$ export TZ=PDT
user@pc:~$ date
 Mi 21. Jun 10:07:19 PDT 2017

However, when I set TZ to CEST-2, it works fine again. I am a bit confused

user@pc:~$ export TZ=CEST-2
user@pc:~$ date
 Mi 21. Jun 12:28:16 CEST 2017

I am working on xUbuntu 16.04 but this behavior is reproducible on a OpenSUSE 42.2 System.

It seems to me that a time zone "ABC+X" is always considered as "UTC+X" when there is no /usr/share/zoneinfo/ABC file (thanks DevilaN for the comment). The string "ABC" is than only inserted into the date string, which is printed out.

Questions:

  1. Is the assumption described above correct?
  2. Why does date print out a time zone abbreviation that is not supported (i.e. not available in /usr/share/zoneinfo)?
  • 2
    You are right. But what is the question? Timezone (TZ variable) is always a name of file in /usr/share/zoneinfo There is no /usr/share/zoneinfo/CEST file so default UTC is being used. It is your fault that you've selected name which can be confused with time name. Because whenever you are using zone, i.e. usr/share/zoneinfo/Europe/Warsaw, there are Central Europe SUMMER time and CET (Central Europe Time) - it depends on time changing periods within this very zone (Europe/Warsaw). – DevilaN Jun 21 '17 at 10:46
  • Ah, ok. I didn't know that. I thought the time zone abbreviations were all predefined. Thanks! – daniel.neumann Jun 21 '17 at 10:51
  • I updated the question. It is not clear to me why date uses a time zone that the system "does not know". – daniel.neumann Jun 21 '17 at 10:59
  • 1
    You may find Specifying the Time Zone with TZ informative – steeldriver Jun 21 '17 at 10:59
  • 1
    @DevilaN, should that be an answer..? (Preferably without explicitly calling someone at fault.) – ilkkachu Jun 21 '17 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.