-----Oorspronkelijk bericht-----
Van: Cottrell, Allin
...
Unix-type systems treat this epoch time as a signed integer, so negative offsets
relative to midnight of 1969-12-31/1970-01-01 can be represented. MS
Windows treats it as an unsigned integer and so cannot handle prior dates.
I think on MS Windows time_t is also a signed integer (int64); see
https://docs.microsoft.com/en-us/cpp/c-runtime-library/standard-types?vie...
Also, mktime could not have -1 as a return value if time_t was unsigned.
Rather it's the implementation that refuses to deal with dates before 1-1-1970; see
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mktime-m...
BTW, this behavior is not prohibited by the Posix and ISO-C specifications, so there might
also be Unix systems with
similar behavior. See
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#...
The MS Windows API can deal with dates from 1-1-1601; it measures time in 100-nanoseconds,
and contrary to time_t, this ìs an unsigned integer. See
https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinba...
If you think about it for a moment, it's clear that figuring the
offset in seconds of a
given date from a given benchmark (the aforementioned start of 1970) is not at
all trivial -- think of leap seconds, never mind leap years. So I doubt there's
anything we can do about this other than post a warning.
The Posix specification does not require to take leap seconds into account, only leap
days: "The relationship between the actual time of day and the current value for
seconds since the Epoch is unspecified. How any changes to the value of seconds since the
Epoch are made to align to a desired relationship with the current actual time is
implementation-defined. As represented in seconds since the Epoch, each and every day
shall be accounted for by exactly 86400 seconds." The difficulty seems to lie more in
the difference between local time and UTC, and whether DST should be taken into account,
but these are probably best specified at the user level in the call to strptime.
There are free versions of mktime in glibc, gnulib, and newlib. The newlib version looks
simpler to implement than the glibc and gnulib versions; the strptime version from
Kungliga Tekniska Högskolan is also in newlib.
Kees