[tz] strftime %s

Guy Harris gharris at sonic.net
Sat Jan 13 20:19:27 UTC 2024


On Jan 13, 2024, at 8:43 AM, Brooks Harris via tz <tz at iana.org> wrote:

> I like Steve's idea of including a tm_time_t member in struct tm. I use something like this in my internal processes.
> 
> it means a function such as GetUT(tm* ptm) can just return the tm_time_t value.

Or you could just avoid calling GetUT(), and just *use* the tm_time_t value, rather than defining a function that needs to remind people, in its documentation, that you need to have arranged that the tm_time_t value has been set in the structure before calling that function, and then deal with all the people who can't be bothered to Read The Fine Manual and ask why their program is giving random results for calls to GetUT().

> This makes many typical operations simple and fast.

As long as you have arranged that tm_time_t is set, perhaps by calling a function such as mktime() which isn't as simple and fast as that.

> It seems straight forward that localtime() could set tm_time_t.

Not only *could* (given that it's passed a time_t as its argument), but *should* do so (given that, as per the above, plenty of programmers will just assume it's been set).

> However, as you point out, you still need mktime() to compute the current time_t in cases where parts of the broken-down-time have been intentionally altered.

Or in cases where tm_time_t wasn't set in the first place.

Given that mktime() cannot determine whether it's been set, this means that mktime() must *always* do the conversion work.

> mktime() could update the tm_time_t member.

It should *always* set tm_time_t.


More information about the tz mailing list