Re: Algorithm to exploit 32 bit time functions to do time zone calculations

Thorsten Glaser <[email protected]> Wed, 17 Sep 2008 22:21:18 +0000 (UTC)
Newsgroups gmane.os.miros.general,gmane.comp.lib.libtai
Message-ID <[email protected]>
Michael G Schwern dixit:

>Odds are, it
>won't get updated.

True=E2=80=A6

>Maybe you can shed some light on this problem, what to do about year 0?

I actually haven=E2=80=99t thought about year 0, since localtime/mktime do =
that,
and mjd2tm and tm2mjd from DJB code. I think it=E2=80=99s illegal, isn=E2=
=80=99t it?

>Right now the only limit I have on dates is the limit of what Time64_T
>can store. Does it make sense to stop at 0?

No, it makes sense to not stop. The thing is, mktime() and gmtime()
*must* have full round-trip capabilities (GNU autoconf checks for that
before it uses it), which is why, for example, my tai64_t data type does
not exactly store what DJB calls a TAI timestamp. There is a small wrap-
around at about 0x8000000000000000 (time_t) / 0xC000000000000000 (tai64_t)
of 10 (I think, due to the leap seconds) seconds. So, for whatever value
you have in whatever representation (time_t, tai64_t, struct tm), all of
these must have full round-trip capabilities (with the possible exception
that struct tm with a 64-bit year can go beyond the 64-bit time_t value
scale, but then, a 32-bit year does the same for a 32-bit time_t, so this
is no change).

>localtime()... well, localtime() gets absurd real fast.  Gregorian/Julian
>calendar shifts.

Mh. Maybe a struct tm.tm_year is always Gregorian? Have a look, while at
it, at the "%J" strftime modifier (and, especially, my implementation of
it, using the tm2mjd function). This will get you Julian days, but nothing
in Unix has them split off into a calendar time kind of structure.

So I think you don=E2=80=99t need to worry about THAT. That=E2=80=99s appli=
cation layer
to do, similar to hebrew, muslim, asian etc. calendars. And at that, it
REALLY gets absurd (cf. http://blogs.msdn.com/michkap/default.aspx), but
that=E2=80=99s not the (our) OS=E2=80=99 job to worry about.

However, for =E2=80=9Cabsurd=E2=80=9D years, the OS=E2=80=99 own functions =
might go crazy. Too
bad we can=E2=80=99t access the OS=E2=80=99 own time zone table (I need to =
get the info
for leap seconds out of it, for example).

bye,
//mirabilos
--=20
Sometimes they [people] care too much: pretty printers [and syntax highligh=
-
ting, d.A.] mechanically produce pretty output that accentuates irrelevant
detail in the program, which is as sensible as putting all the prepositions
in English text in bold font.=09-- Rob Pike in "Notes on Programming in C"