Jan. 10, 2024
4:35 p.m.
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@des.no