4

On my Manjaro linux box, I have a file /etc/timezone which contains:

Asia/Bangkok

Another Manjaro forum user also has the same file. That thread on the whole contains some prior art on this question.

What's strange is that timedatectl status doesn't use this file to report Region/City. Here's the initial status:

$ timedatectl status                                          
                      Local time: Fri 2018-06-29 11:01:28 +07       
                  Universal time: Fri 2018-06-29 04:01:28 UTC    
                        RTC time: Fri 2018-06-29 04:01:28        
                       Time zone: Asia/Bangkok (+07, +0700)             
       System clock synchronized: no                          
systemd-timesyncd.service active: no                              
                 RTC in local TZ: no                            

Now I overwrite the /etc/localtime symlink with contents of the file it points to:

$ sudo ln -f "$(realpath /etc/localtime)" /etc/localtime          
$ timedatectl status                                           
                      Local time: Fri 2018-06-29 04:04:03 UTC
                  Universal time: Fri 2018-06-29 04:04:03 UTC
                        RTC time: Fri 2018-06-29 04:04:04
                       Time zone: n/a (UTC, +0000) 
       System clock synchronized: no                               
systemd-timesyncd.service active: no
                 RTC in local TZ: no  

Note the local time change to match UTC, and then/a timezone.

So, timedatectl doesn't read from /etc/timezone, and timedatectl set-timezone doesn't write to /etc/timezone also.

Besides that guess, my /etc/timezone is a mystery.

  1. What writes it?
  2. What reads it?
  3. What for?
  • 1
    This behaviour of timedatectl is not "strange". As Stephen Kitt told you in unix.stackexchange.com/a/451714/5132 , this is the normal behaviour of timedatectl. The behaviour on Debian is an exception, not the rule. – JdeBP Jun 29 '18 at 6:27
  • @JdeBP It's the presence of /etc/timezone that is strange because I'm not running Debian. – Tom Hale Jun 30 '18 at 6:24
6

GNU libc (and thus any non-embedded Linux), reads /etc/localtime to determine the system's time zone (the default timezone if not overridden by the TZ environment variable or by an application-specific setting). *BSD does the same thing. Some embedded Linux systems do things differently.

/etc/localtime should be a symbolic link to a file under /usr/share/zoneinfo/. Normal applications don't mind, they only read the contents of the file, but system management utilities such as timedatectl care more because they can also change the setting, and they would do that by changing the target of the symbolic link.

Java does (or did?) things differently: it reads /etc/timezone, which contains a timezone name, which should be the path to a file relative to /usr/share/zoneinfo. I'm not aware of any other program that uses /etc/timezone, and I don't know why Sun chose to do things differently from the rest of the world.

| improve this answer | |
  • Yes you do. You referenced it in your 2011 answer. Sun/Oracle chose to do things the same as someone else. It just chose Debian/Ubuntu as that someone else, adopting the /etc/timezone mechanism in 2009. – JdeBP Jun 29 '18 at 6:42
  • @JdeBP Sun most definitely doesn't do the same thing as Debian. I've never found anything that uses /etc/timezone other than Java, and I've been a Debian user for close to two decades. – Gilles 'SO- stop being evil' Jun 29 '18 at 7:15
  • There are still a few packages in Debian which use /etc/timezone rather than /etc/localtime, e.g. cron or cups. See this source search for the full list. Some upstream programs use it too — in some cases, in preference to /etc/localtime (e.g. FreeRDP), in other cases, as a fallback (e.g. Firefox, Chrome, GNOME). /etc/localtime in glibc dates back to some time in 1992, by which time the development of Java had already started. It could well be a case of cargo-culting of course. – Stephen Kitt Jun 29 '18 at 7:24
  • It might be interesting to look at what early JVMs did on platforms without symlinks... – Stephen Kitt Jun 29 '18 at 7:25
  • You need to read the very bug report that you yourself pointed to in 2011. There the statement that this behaviour comes to Java from Debian is, plain as day, dated 2009-08-07. And we also know that this is a Debianism from the fact that, as I and Stephen Kitt have already pointed out, timedatectl has been patched on Debian to include this Debianism, the patch itself also explaining that it is a Debianism as does this manual. A Debian user for two decades will know where to find Debian Bugs 803144, 726256, and 726996. – JdeBP Jun 29 '18 at 7:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.