I’ve been slow to finish testing my C++ time zone code because I’ve had other things to do; but I think I have it ready for prime time.
But now, in the spirit of the analysis paralysis anti-pattern 😎 (I’m having fun in my retirement, don’tcha know), I’ve decided that I’d like to make it magically portable to the Mac if I can.
1. Does the Mac have the Zoneinfo data somewhere?
2. Do you have POSIX-style environment variables (possibly called TZ_ROOT and TZ) for
a. the directory where the Zoneinfo compiled binaries are found, and/or
a. your local time zone?
If Macs are at all Linux-like except for having the environment variables, TZ_ROOT could be
And for those doing C++ work with some version of GCC,
3. is there some macro or other predefined identifier that says we’re compiling for a Mac rather than some other POSIX-like O/S?
I could probably go to an Apple store, fire up a Korn (or other) shell, and find out what I need for myself; but I’m hoping that there’s somebody reading this blog who already knows the answers off the top of their head.
Thanks.
Update: thanks to robert79 for some good information about Macs.
It looks like they work pretty much like Linux, except that the filesystem has no symbolic link called localtime, so I still have no clue how a program can discover what the local time zone is. There’s certainly some way to set the time zone through the UI, but I still need to find out how to discover that setting programmatically. Maybe Google will help.
Update2: well, that was easy. I should have just Googled from the get-go.
It seems that, in POSIX systems generally, /etc/localtime is usually a symbolic link to the real file. There should also be a file called
My Debian Linux box, a VPS actually, is somewhere in England; so /etc/localtime is a symlink to
I don’t need any code changes, just some remarks in the documentation that the library will work on a Mac; and I still have to proofread that anyway.
Thanks again to robert79.
robert79 says
The /usr/share/zoneinfo directory exists on my Mac, as far as I can tell there is no environment variable called TZ_ROOT or TZ.
billseymour says
Thanks; it probably works just like Linux and I don’t have to do anything special. 😎
If you
cd /usr/share/zoneinfo
andls -l local*
, do you see something like:?
robert79 says
nope
$ ls -al
total 656
-rw-r–r– 1 root wheel 6 Jan 18 00:04 +VERSION
drwxr-xr-x 69 root wheel 2208 Jan 31 04:14 .
drwxr-xr-x 5 root wheel 160 Jan 31 04:14 ..
drwxr-xr-x 56 root wheel 1792 Jan 31 04:14 Africa
drwxr-xr-x 148 root wheel 4736 Jan 31 04:14 America
… bunch of timezones omitted …
-rw-r–r– 1 root wheel 114 Jan 18 00:04 Zulu
-rw-r–r– 1 root wheel 4791 Jan 18 00:04 iso3166.tab
-rw-r–r– 1 root wheel 3388 Jan 18 00:04 leapseconds
-rw-r–r– 1 root wheel 3552 Jan 18 00:04 posixrules
-rw-r–r– 1 root wheel 109247 Jan 18 00:04 tzdata.zi
-rw-r–r– 1 root wheel 18846 Jan 18 00:04 zone.tab
billseymour says
Interesting.
My Debian Linux box (a VPS actually) is somewhere in England; so is a symbolic link to which, in turn, is another symlink to
/usr/share/zoneinfo/localtime
/etc/localtime
/usr/share/zoneinfo/Europe/London
.How is the local time zone identified on a Mac?
robert79 says
I have no clue… I’ve never looked into timezone stuff on this level on Mac/Linux before!
But my experience is that the terminal (shell) is enough like Linux for most of the stuff I need to do with it.
was ist eine wg says
Excellent way of telling, and nice post to obtain data regarding my presentation subject matter, which i am
going to present in university.
billseymour says
was ist eine wg: Good luck on your presentation.
Do you want to know what a WG is? 😎 For me, it’s ISO/IEC JTC1 SC22 WG21.
ISO: The International Organization for Standardization
IEC: The International Electrotechnical Commission
JTC1: Joint Technical Committee 1 – Information Technology
SC22: Subcommittee 22 – Programming Languages and their Environments
WG21: Working Group 21 – C++