Time Zones in C++

I think I have my timezone class ready for prime time, so I should be just about ready to finish the larger civil time library (which I put on hold because a couple of the classes depend on timezone).

But as I write this, I remember that there’s one thing I haven’t tested yet:  the option of reading TZ and TZ_ROOT environment variables using std::getenv() before the timezone class gets used for anything.  I do that magically with some tricky code that has the odor of the poltergeist anti-pattern; so I need to create the TZ and TZ_ROOT environment variables on my Windows box and make sure that that works.  I don’t see any reason why it won’t, so I’ll say tentatively that I’m done.

Questions for Mac Users

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 /usr/share/zoneinfo”; and TZ could be localtime or, in the U.S. central time zone for example, either America/Chicago or CST6CDT,M3.2.0,M11.1.0”.

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.


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 /etc/timezone.

My Debian Linux box, a VPS actually, is somewhere in England; so /etc/localtime is a symlink to /usr/share/zoneinfo/Europe/London and /etc/timezone is a plain text file that contains just Europe/London”.

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.

On the Cancer Front

As I’ve said before, I’m participating in a study of the effectiveness of prophylactic radiation treatments to keep small cell cancer out of the brain.  That’s currently the standard care, but it’s based on a study from back in the ’70s (IIRC) and n was small.

This study is random but not blind, so I know that I was randomized into the control group.  I’ll be getting everything except the actual radiation.

On Monday, I had some blood drawn and the nurse who runs the study at my particular hospital gave me the test of cognitive abilities that, I guess, is the one that Trump misremembered; yesterday, I had a CT scan and an MRI; and today I had follow-up appointments with the chemo and radiation oncologists.  IIRC, the current plan is to do that every three months for a year, then every six months for the second and last year.

The blood work and the MRI turned out fine (I wasn’t told whether I’m thinking straight ๐Ÿ˜Ž ), but the CT scan showed what could possibly me more cancer, this time in a lymph node.  I’ll be getting a PET scan on Monday, and then I’ll meet with the chemo doctor, and maybe the radiologist as well, on the 27th.  They might also want me to get a biopsy.  We’ll see how it goes.  I was told that, in any event, I’ll still be in the study and so still be doing my small bit to add to human knowledge.

One thing that occurs to me:  if Trump wins in November, this might be a good time to check out. ๐Ÿ˜Ž

Time Zones

I’ve been debugging my timezone stuff somewhat casually, but I think I have it to the point where I’m willing to admit that I wrote it. ๐Ÿ˜Ž

This paper also references a trivial library that I’ve mentioned before.

If anybody who cares can think of any cool features that I should add, please let me know, either in the comments or in a private e-mail message.

I can now finish my larger civil time library which contains classes that are intended to be the C++ equivalents of SQL’s datetime types, which in turn will be part of a database access library.  (I’m still having fun in my retirement.)

Some Fun Time Zone Geekiness

There were a few e-mail messages on the FtB backchannel a little while ago.  An FtB blogger who lives in Ireland was wondering when the next FtB Podish-Sortacast will happen (https://freethoughtblogs.com/pharyngula/2024/03/09/in-my-prime/, scroll down a bit), probably just under an hour from when I get this posted.

That got me to thinking about civil time in the Irish Republic.  It winds up that they observe the same time as Great Britain and Northern Ireland, except they get there with rather tortured reasoning.

In the U.K., they switch from “Greenwich Mean Time” (GMT, same as UTC+0) to “British Summer Time” (BST, UTC+1) on the last Sunday in March at 01:00:00 local wall clock time, and they switch back from BST to GMT on the last Sunday in November at 02:00:00 local wall clock time.

In Ireland, they switch from ”Irish Standard Time” (IST, UTC+1) to GMT on the last Sunday in November at 02:00, and they switch back from GMT to IST on the last Sunday in March at 01:00.

Yes, really. Go figure. ๐Ÿ˜Ž

The POSIX TZ environment variable for Europe/London:  GMT0BST,M3.5.0/1,M10.5.0
The POSIX TZ environment variable for Europe/Dublin:  IST-1GMT0,M10.5.0,M3.5.0/1

Why did they bother?

A Couple of C++ Quickies

I wrote two fairly trivial libraries to support my development of the timezone class that I’ve mentioned before.

1.  Reading Directories in C++ describes a class that loops through directories.  It’s portable to both POSIX and Windows so that you don’t have to do that in two very different ways.

2.  Getting Zoneinfo Data on Windows describes a simple way to do what the title says along with a couple of functions that let you create and delete symbolic links on Windows.

Both of those are really old news, and neither has any great ideas of my own, so all that code is in the public domain.

The timezone class is finished, but I still need to do some testing before I release the code to the world and, perhaps, embarrass myself. ๐Ÿ˜Ž  I hope to have that done later today.