Today I learned that glibc has a broken %s implementation in strftime. It applies the timezone even when we want UTC...

https://github.com/curl/curl/issues/22038

%time{%s} in --write-out returns wrong epoch on non-UTC hosts · Issue #22038 · curl/curl

I did this Summary curl --write-out '%time{%s}' (and %time{%s.%f}) outputs an epoch value that is offset by the local timezone offset from UTC. On a host in Asia/Shanghai (UTC+8), the value is cons...

GitHub
@bagder How is this broken? It's a non-standard extension to strftime(), so it can be whatever it wants.
@harrysintonen I would still say that applying the timezone is wrong, but sure it's just my opinion. I'm not going to insist

@bagder Man page says "The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). (TZ) (Calculated from mktime(tm).)"

Everything there suggests timezone is applied.

Not even arguing if that makes sense, just that it is documented to do that.

@harrysintonen I'll still claim that is wrong, but documented =)
@bagder @harrysintonen gnu manpages once again serving as a comprehensive bug tracker
@bagder Yeah, a lot of things are documented and still very wrong. :>
@bagder ah as soon as any of my code touches UTC in any way I just know I’m about to go down a 2-3 day rabbit hole

@imclaren Depends on programming language, and within programming language on toolkit, I'd say?

@bagder

@taschenorakel @bagder respectful strong disagree. UTC is like complex concurrency. It’s a bag of hard even with beautiful programming languages.

@imclaren UTC itself or conversion from and to local time?

While huge effort is needed to compute the official UTC timestamp, for us mere mortals it's just "Whatever number my NTP server of trust gives me", not?

Biggest issue, as with all wall times: It is not monotonic...

@bagder

@taschenorakel @bagder conversions. Although I’ve never seen live code dealing with utc that doesn’t involve conversions.

Obligatory xkcd: https://xkcd.com/1883/

Supervillain Plan

xkcd

@imclaren Yes, but this is local times, not UTC. Local times are complicated.

@bagder

@taschenorakel @bagder maybe it’s just me but I have never worked on prod code that didn’t involve conversion to localtime. For me, working with utc means working with localtime
@bagder oooooof, that's useful to know about. Thank you for mentioning it.

@bagder Does the refrence implementation in IANA tzdb handle it differently?

There was a discussion about it a few years ago on the tz mailing list: https://mm.icann.org/pipermail/tz/2024-January/058539.html

[tz] strftime %s