[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: os.time() and the last second of 1969
- From: Sean Conner <sean@...>
- Date: Sat, 12 Feb 2022 17:32:26 -0500
It was thus said that the Great Dirk Jagdmann once stated:
> It seems as if all these implementations are not checking the values of
> the struct tm member variables for a valid range, but simply take these
> integer values and use them in their formula to calculate the timestamp
> value.
Here's what the standard says about mktime():
The mktime function converts the broken-down time, expressed as
local time, in the structure pointed to by timeptr into a calendar
time value with the same encoding as that of the values returned by
the time function. The original values of the tm_wday and tm_yday
components of the structure are ignored, and the original values of
^^^^^^^^^^^^^^^^^^^^^^^^^^
the other components are not restricted to the ranges indicated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
above.) On successful completion, the values of the tm_wday and
^^^^^
tm_yday components of the structure are set appropriately, and the
other components are set to represent the specified calendar time,
but with their values forced to the ranges indicated above; the
final value of tm_mday is not set until tm_mon and tm_year are
determined.
(Section 7.23.2.3 of the C99 standard)
The standard does not say what to do when the original values exceed the
ranges specified:
int tm_sec; // seconds after the minute - [0, 60]
int tm_min; // minutes after the hour - [0, 59]
int tm_hour; // hours since midnight - [0, 23]
int tm_mday; // day of the month - [1, 31]
int tm_mon; // months since January - [0, 11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday - [0, 6]
int tm_yday; // days since January 1 - [0, 365]
int tm_isdst; // Daylight Saving Time flag
(Section 7.23.1 of the C99 standard)
-spc