I know sudo tzsetup
will prompt me to change time zone settings on FreeBSD.
➥ How can I see the current time zone settings, without making changes?
I know date
shows me current time. For example:
Sun Dec 9 05:45:25 UTC 2018
…which I assumes mean the current default time zone is UTC.
But in this case:
Sat Dec 8 21:52:04 PST 2018
The PST
is not a true time zone. Such 2-4 letter codes are neither standardized nor unique. True time zones are in the Continent/Region
format such as Europe/Africa
or Africa/Tunis
(see Wikipedia).
How can I see the true time zone set as default?
This posting mentions using an environment variable TZ
.
export TZ=America/Los_Angeles
But my FreeBSD 11.2 machine does not have such a variable set. So I suspect that is not the driving factor.
Best Answer
The TLDR answer is:
The current timezone is stored in the file
/etc/localtime
. As @Kusalananda remarks this can be a symbolic link. But as @JdeBP hints that on FreeBSD this file is normally copied from/usr/share/zoneinfo
during setup.These files originates from textual descriptions in contrib/tzdata
This information is then compiled into a binary format using zic and the format is specified in tzfile
I do not know of a built in utility which directly parses this file. But it should be easy to write in C with the documentation at hand. If we want to stick with what come out of the box we can look at it using
hexdump
.Or if we just want to look at the magic marker:
Or the fields:
Using:
Results in my case:
Then we do the following math to figure out where the first
ttinfo
starts:The wheels slowly falls of:
With these numbers I am probably a little off. And this is truly a masochistic way of dealing with it. So I am stopped just short of finding the gold using
tt_abbrind
But if we look at the bottom of the tzfile specification we find this little nugget:
So it is as easy as:
When you look closer you will notice that
/etc/localtime
does not contain anyContinent/Region
setting! But as the file is copied from/usr/share/zoneinfo
you can compare them and find the probable file. I have not dived deep enough to confirm if/usr/share/zoneinfo
might contain duplicates. But for me - this works nicely:We iterate through all files in
/usr/share/zoneinfo
and compare each of them with/etc/localtime
.cmp
using the-s
parameter will not display anything and only exit using a value. If the value is zero we will print the name. When printing the name we usecut
to remove the first 21 characters to getContinent/Region