Paul Eggert via tz wrote in
<[email protected]>:
|On 8/5/26 16:33, Steffen Nurpmeso via tz wrote:
|> A maintained variant of Mail/mailx uses a different approach which
|> hopefully works (with/out .tm_gmtoff) correctly.
|
|Its "ifdef mx_HAVE_TM_GMTOFF" code looks OK, but when mx_HAVE_TM_GMTOFF
|is not defined that code is obviously wrong near the start or end of the
|year. For a better approach, see zdump.c's gmtoff function.
I am still asleep and my head is with all the (other) animal
friends that i care of. And never being of the bright natural
science sort anyway, after that right wing math teacher (whose
wife then became minister of education here in hesse) brought me
to my knees in the fifth class, at least.
But i find your approach -- from the look -- excessive? If
localtime and gmtime both refer to the same clock_gettime, then at
maximum there can be "one day" difference; i was not up2date, but
a search says currently the maximum is +14 and -11, so local and
UTC differ by ~1/2 day at most.
Normally the thing is plain this:
rv = ((((localp_or_nil->tm_hour - utcp_or_nil->tm_hour) * 60) +
(localp_or_nil->tm_min - utcp_or_nil->tm_min)) * 60) +
(localp_or_nil->tm_sec - utcp_or_nil->tm_sec);
However, the day may flip, which means the above must be corrected
by an entire day, forward or backward, as appropriate.
if((t = (localp_or_nil->tm_yday - utcp_or_nil->tm_yday)) != 0)
Aah, *thank you*. Yes, there was a change due to the "Dublin
stuff", the software did
- if((t2 = mktime(gmtime(&t))) == (time_t)-1)
- goto jinvalid;
- tzdiff = t - t2;
- if((tmptr = localtime(&t)) == NULL)
- goto jinvalid;
- if (tmptr->tm_isdst > 0)
- tzdiff += 3600; /* TODO [.] */
- t -= tzdiff;
before, but of course the t==1 in the following is wrong, because
tm_yday is 0 based!
- rv += (t == 1) ? S(s32,su_TIME_DAY_SECS) : -S(s32,su_TIME_DAY_SECS);
Instead i'll do (i think now, but will look again)
if(t < 0 && localp_or_nil->tm_yday == 0)
t = 1;
rv += (t == 1) ? S(s32,su_TIME_DAY_SECS) : -S(s32,su_TIME_DAY_SECS);
The change is not released but for an -alpha, luckily!!
Again thank you very much for mentioning it.
Having said that i find your zdump.c variant still very excessive?
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)