[tz] strftime %s

Steffen Nurpmeso steffen at sdaoden.eu
Thu Jan 11 22:30:58 UTC 2024


Paul Eggert via tz wrote in
 <45af6b1e-4bc8-4b8e-86f5-101046061434 at cs.ucla.edu>:
 |On 2024-01-11 11:09, Paul Gilmartin via tz wrote:
 |> That is, it is the responsibility of the programmer to call strftime()
 |> with a TZ matching that corresponding to struct tm.  I take this to
 |> mean that gmtime corresponds to GMT0.  There is no need to ad a
 |> time_t value.
 |
 |Yes, after looking at this a bit more I'm becoming more inclined to not 
 |add a strftime_z (and strftime_lz). It's easy to generate the equivalent 
 |of %s with sprintf on the corresponding time_t value, and none of the 
 |other strftime formats should care which timezone was used to generate \
 |them.
 |
 |%z and %Z should be calculated from tm_gmtoff and tm_zone (when 
 |available) rather than by invoking mktime (which is the best you can do 
 |when they're not available). The next POSIX draft says something along 
 |these lines, although it botches the details (which admittedly are messy).
 |
 |If I understand things correctly, it's impossible for an implementation 
 |to conform to both POSIX-2017 and draft next POSIX in this area. Oh well.

To point out that the standard text is identical except for an ISO
8601 update from 2004 to 2019 and hinting the involved structure
fields.  So it seems to me that POSIX now includes the fields
necessary to actually perform the necessary operation; possibly at
least 25+ years too late, given a72c4a2a74

  Author:     Arthur David Olson <ado at elsie>
  AuthorDate: 2000-04-17 10:08:31 -0400
  Commit:     Paul Eggert <eggert at cs.ucla.edu>
  CommitDate: 2012-07-18 03:02:34 -0400

      Eggert mods plus cleanups

      SCCS-file: strftime.c
      SCCS-SID: 7.59

where you say

  +                               if (t->tm_isdst < 0)
  +                                       continue;
  +#ifdef TM_GMTOFF
  +                               diff = t->TM_GMTOFF;
  +#else /* !defined TM_GMTOFF */
  +                               /*
  +                               ** C99 says that the UTC offset must
  +                               ** be computed by looking only at
  +                               ** tm_isdst.  This requirement is
  +                               ** incorrect, since it means the code
  +                               ** must rely on magic (in this case
  +                               ** altzone and timezone), and the
  +                               ** magic might not have the correct
  +                               ** offset.  Doing things correctly is
  +                               ** tricky and requires disobeying C99;
  +                               ** see GNU C strftime for details.
  +                               ** For now, punt and conform to the
  +                               ** standard, even though it's incorrect.
  +                               */
  +                               diff = -(t->tm_isdst ? altzone : timezone);

where altzone is precalculated from some (tz_)gmtoff that in fact
is present in Mr. Olson's package aka ado at elsie since 1986-01-13
(164b93d818) -- wow!  ISO C.  And it still has no bit enums.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


More information about the tz mailing list