Collin Funk <[email protected]> writes:
>> Also the /usr/share/zoneinfo dir is parameterized
>> both at build and runtime through TZDIR define and $TZDIR respectively.
>> So we'd have to use the TZDIR define and getenv("TZDIR") to get
>> the appropriate directory.
>> Also one could use #ifdef TZDIR, to restrict the code above to
>> supported platforms.
>
> Is there anywhere where /usr/share/zoneinfo isn't the correct location?
> That works on macOS, which typically has a stranger layout, e.g.,
> /Users/collinfunk instead of /home/collinfunk or /usrc/home/collinfunk.
After doing a bit more research apparently AIX and Solaris use
/usr/share/lib/zoneinfo. Haiku seems to not use a zoneinfo directory or
equivalent.
> I guess Windows will likely be something strange. Perhaps it can be
> determined from the generated lib/configmake.h. I'll try that. It would
> be easy to parameterize if it were not for cross-compilation.
Windows stores tzdb in the registry. Sigh...
>> I'm thinking all of the above might be encapsulated
>> in a tzfile() function, returning NULL if not found?
>>
>> So in summary pseudo code for this might be:
>>
>> #ifdef TZDIR
>> if (returned_UTC_offset == 0
>> && TZ != UTC[-+]?0*
>> && ! tzfile())
>> dbg_printf (_("warning: TZ=\"%s\" falling back to UTC\n"), tzstring);
>> #endif
I think you would have to pass tzfile a string, since it may be set
using:
$ date -d 'TZ="..." ...'
That part is simple. The trickier part is warning for invocations like:
$ TZ=invalid date
I'll have to research how well supported /etc/localtime is, or what
other equivalents there are.
Collin