cpython: 8a504694d92f (original) (raw)
--- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -15,6 +15,12 @@ static struct tm *localtime_r(const time return result; return NULL; } +static struct tm *gmtime_r(const time_t *timep, struct tm *result) +{
+} #endif /* Differentiate between building the core module and building extension @@ -2517,14 +2523,13 @@ date_new(PyTypeObject *type, PyObject *a static PyObject * date_local_from_object(PyObject *cls, PyObject *obj) {
- struct tm tm; time_t t; if (_PyTime_ObjectToTime_t(obj, &t, _PyTime_ROUND_FLOOR) == -1) return NULL;
#ifdef EINVAL if (errno == 0) @@ -2535,9 +2540,9 @@ date_local_from_object(PyObject *cls, Py } return PyObject_CallFunction(cls, "iii",
tm->tm_year + 1900,[](#l1.37)
tm->tm_mon + 1,[](#l1.38)
tm->tm_mday);[](#l1.39)
tm.tm_year + 1900,[](#l1.40)
tm.tm_mon + 1,[](#l1.41)
tm.tm_mday);[](#l1.42)
} /* Return new date from current time. @@ -4194,8 +4199,8 @@ datetime_new(PyTypeObject type, PyObjec return self; } -/ TM_FUNC is the shared type of localtime() and gmtime(). */ -typedef struct tm *(*TM_FUNC)(const time_t timer); +/ TM_FUNC is the shared type of localtime_r() and gmtime_r(). */ +typedef struct tm *(TM_FUNC)(const time_t timer, struct tm); / As of version 2015f max fold in IANA database is
- 23 hours at 1969-09-30 13:00:00 in Kwajalein. */ @@ -4244,11 +4249,10 @@ static PyObject * datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us, PyObject *tzinfo)
#ifdef EINVAL if (errno == 0) errno = EINVAL; @@ -4256,20 +4260,20 @@ datetime_from_timet_and_us(PyObject *cls return PyErr_SetFromErrno(PyExc_OSError); }
- year = tm->tm_year + 1900;
- month = tm->tm_mon + 1;
- day = tm->tm_mday;
- hour = tm->tm_hour;
- minute = tm->tm_min;
- year = tm.tm_year + 1900;
- month = tm.tm_mon + 1;
- day = tm.tm_mday;
- hour = tm.tm_hour;
- minute = tm.tm_min; /* The platform localtime/gmtime may insert leap seconds,
* indicated by tm->tm_sec > 59. We don't care about them,[](#l1.86)
* indicated by tm.tm_sec > 59. We don't care about them,[](#l1.87) * except to the extent that passing them on to the datetime[](#l1.88) * constructor would raise ValueError for a reason that[](#l1.89) * made no sense to the user.[](#l1.90) */[](#l1.91)
result_seconds = utc_to_seconds(year, month, day, @@ -4357,7 +4361,7 @@ datetime_datetime_now_impl(PyTypeObject return NULL; self = datetime_best_possible((PyObject *)type,
tz == Py_None ? localtime : gmtime,[](#l1.105)
if (self != NULL && tz != Py_None) { /* Convert UTC to tzinfo's zone. */tz == Py_None ? localtime_r : gmtime_r,[](#l1.106) tz);[](#l1.107)
@@ -4372,7 +4376,7 @@ datetime_datetime_now_impl(PyTypeObject static PyObject * datetime_utcnow(PyObject *cls, PyObject *dummy) {
} /* Return new local datetime from timestamp (Python timestamp -- a double). */ @@ -4391,7 +4395,7 @@ datetime_fromtimestamp(PyObject *cls, Py return NULL; self = datetime_from_timestamp(cls,
tzinfo == Py_None ? localtime : gmtime,[](#l1.123)
if (self != NULL && tzinfo != Py_None) { @@ -4409,7 +4413,7 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *result = NULL; if (PyArg_ParseTuple(args, "O:utcfromtimestamp", ×tamp))tzinfo == Py_None ? localtime_r : gmtime_r,[](#l1.124) timestamp,[](#l1.125) tzinfo);[](#l1.126)
result = datetime_from_timestamp(cls, gmtime, timestamp,[](#l1.132)
return result; } @@ -5032,37 +5036,51 @@ local_timezone_from_timestamp(time_t tim { PyObject *result = NULL; PyObject *delta;result = datetime_from_timestamp(cls, gmtime_r, timestamp,[](#l1.133) Py_None);[](#l1.134)
if (errno == 0)[](#l1.149)
errno = EINVAL;[](#l1.150)
#else /* HAVE_STRUCT_TM_TM_ZONE */ { PyObject *local_time, *utc_time;
struct tm *utc_time_tm;[](#l1.163)
struct tm utc_time_tm;[](#l1.164) char buf[100];[](#l1.165)
strftime(buf, sizeof(buf), "%Z", local_time_tm);[](#l1.166)
strftime(buf, sizeof(buf), "%Z", &local_time_tm);[](#l1.167) zone = buf;[](#l1.168)
local_time = new_datetime(local_time_tm->tm_year + 1900,[](#l1.169)
local_time_tm->tm_mon + 1,[](#l1.170)
local_time_tm->tm_mday,[](#l1.171)
local_time_tm->tm_hour,[](#l1.172)
local_time_tm->tm_min,[](#l1.173)
local_time_tm->tm_sec, 0, Py_None, 0);[](#l1.174)
local_time = new_datetime(local_time_tm.tm_year + 1900,[](#l1.175)
local_time_tm.tm_mon + 1,[](#l1.176)
local_time_tm.tm_mday,[](#l1.177)
local_time_tm.tm_hour,[](#l1.178)
local_time_tm.tm_min,[](#l1.179)
local_time_tm.tm_sec, 0, Py_None, 0);[](#l1.180) if (local_time == NULL) {[](#l1.181) return NULL;[](#l1.182) }[](#l1.183)
utc_time_tm = gmtime(×tamp);[](#l1.184)
utc_time = new_datetime(utc_time_tm->tm_year + 1900,[](#l1.185)
utc_time_tm->tm_mon + 1,[](#l1.186)
utc_time_tm->tm_mday,[](#l1.187)
utc_time_tm->tm_hour,[](#l1.188)
utc_time_tm->tm_min,[](#l1.189)
utc_time_tm->tm_sec, 0, Py_None, 0);[](#l1.190)
if (gmtime(×tamp, &utc_time_tm) == NULL) {[](#l1.191)
if (errno == 0)[](#l1.193)
errno = EINVAL;[](#l1.194)
PyErr_SetFromErrno(PyExc_OSError);[](#l1.196)
return NULL;[](#l1.197)
}[](#l1.198)
utc_time = new_datetime(utc_time_tm.tm_year + 1900,[](#l1.199)
utc_time_tm.tm_mon + 1,[](#l1.200)
utc_time_tm.tm_mday,[](#l1.201)
utc_time_tm.tm_hour,[](#l1.202)
utc_time_tm.tm_min,[](#l1.203)
utc_time_tm.tm_sec, 0, Py_None, 0);[](#l1.204) if (utc_time == NULL) {[](#l1.205) Py_DECREF(local_time);[](#l1.206) return NULL;[](#l1.207)