[tz] strftime %s

Paul Eggert eggert at cs.ucla.edu
Fri Jan 12 23:17:07 UTC 2024


On 2024-01-12 11:47, Steve Summit via tz wrote:

> I don't know off the top of my head how the "official" date
> command implemented this.

("official" :-)?

As I vaguely recall, SunOS "date" implemented %s by 1996 and inspired by 
that, I added support for %s to tzcode's strftime.c around then. See:

https://github.com/eggert/tz/commit/1efa2d66a41913eeaaba1f804ac91e408d3057ce
https://mm.icann.org/pipermail/tz/1996-January/009464.html


> found myself writing code that took a
> "strftime-plus-%s" format string, manually scanned for and
> interpolated any %s specifiers, then handed it off to strftime to
> take care of the rest.  This was unremittingly ugly -- but it was
> (to my mind, anyway) still vastly preferable to trying to have
> strftime handle %s by itself, because strftime just doesn't have
> the right information available to it.

Although that's true of current POSIX (which doesn't have %s) it's not 
true for POSIX 202x/D3, which has tm_gmtoff as well as %s. If you have 
tm_gmtoff that's enough info (along with the other struct tm members) to 
implement %s.


> I hope that, in the absence of either of these admittedly radical
> proposals, Posix is at least mandating tm_gmtoff, which we've
> long needed anyway, and which would at least make the implicit
> mktime call, necessitated by %s, a tractable problem.)

Yes, that's what draft POSIX is doing.



More information about the tz mailing list