[tz] strftime %s
Brooks Harris
brooks at edlmax.com
Sat Jan 13 20:39:17 UTC 2024
On 1/13/2024 3:19 PM, Guy Harris wrote:
> 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().
Sure.
>
>> 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.
Sure.
>
>> 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).
Yeah. Just trying to use suggestive language. But, yes, "should",
probably "must".
>
>> 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.
Only if localtime() hasn't already set it. But applications must be
careful to be sure it's set to the current value representing the
broken-down-time. Maybe some sort of 'state' flag is needed, like "not
set", "set by localtime", "set by mktime()"
>
>> mktime() could update the tm_time_t member.
> It should *always* set tm_time_t.
Yes. Just trying to politely suggest the obvious.
So I take it you think providing tm_time_t is not a bad idea, generally?
-Brooks
More information about the tz
mailing list