[tz] strftime %s

Dag-Erling Smørgrav des at des.no
Wed Jan 10 16:35:34 UTC 2024


Currently, strftime() implements %s by calling mktime() and then
printing the result.  This is fine when the struct tm passed to
strftime() came from localtime() but not when it didn't.  A better
solution would be to call timegm() and then manually adjust the result.
Of course that's only possible in the TM_GMTOFF case but that's still
better than nothing.

The first attachment is a program which demonstrates the issue.  It
should print the same value for %s in both cases but doesn't:

% cc -Wall -Wextra -o strftime_s strftime_s.c
% ./strftime_s
local	1704903586 2024-01-10 17:19:46 CET
gm	1704899986 2024-01-10 16:19:46 UTC

The second attachment is my proposed fix.

DES
--
Dag-Erling Smørgrav - des at des.no

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: strftime_s.c
URL: <https://mm.icann.org/pipermail/tz/attachments/20240110/60982376/strftime_s.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strftime_s.diff
Type: text/x-patch
Size: 491 bytes
Desc: not available
URL: <https://mm.icann.org/pipermail/tz/attachments/20240110/60982376/strftime_s.diff>


More information about the tz mailing list