SF bug 660872: datetimetz constructors behave counterintuitively (2.3a1).
This gives much the same treatment to datetime.fromtimestamp(stamp, tz) as
the last batch of checkins gave to datetime.now(tz): do "the obvious"
thing with the tz argument instead of a senseless thing.
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index d81d563..aeccfda 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -3682,8 +3682,7 @@
if (self != NULL && tzinfo != Py_None) {
/* Convert UTC to tzinfo's zone. */
PyObject *temp = self;
- self = PyObject_CallMethod(tzinfo, "fromutc",
- "O", self);
+ self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
Py_DECREF(temp);
}
return self;
@@ -3702,17 +3701,26 @@
static PyObject *
datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
{
- PyObject *self = NULL;
+ PyObject *self;
double timestamp;
PyObject *tzinfo = Py_None;
- static char *keywords[] = {"timestamp", "tzinfo", NULL};
+ static char *keywords[] = {"timestamp", "tz", NULL};
- if (PyArg_ParseTupleAndKeywords(args, kw, "d|O:fromtimestamp",
- keywords, ×tamp, &tzinfo)) {
- if (check_tzinfo_subclass(tzinfo) < 0)
- return NULL;
- self = datetime_from_timestamp(cls, localtime, timestamp,
- tzinfo);
+ if (! PyArg_ParseTupleAndKeywords(args, kw, "d|O:fromtimestamp",
+ keywords, ×tamp, &tzinfo))
+ return NULL;
+ if (check_tzinfo_subclass(tzinfo) < 0)
+ return NULL;
+
+ self = datetime_from_timestamp(cls,
+ tzinfo == Py_None ? localtime : gmtime,
+ timestamp,
+ tzinfo);
+ if (self != NULL && tzinfo != Py_None) {
+ /* Convert UTC to tzinfo's zone. */
+ PyObject *temp = self;
+ self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
+ Py_DECREF(temp);
}
return self;
}
@@ -4404,7 +4412,7 @@
{"now", (PyCFunction)datetime_now,
METH_KEYWORDS | METH_CLASS,
- PyDoc_STR("[tzinfo] -> new datetime with local day and time.")},
+ PyDoc_STR("[tz] -> new datetime with tz's locl day and time.")},
{"utcnow", (PyCFunction)datetime_utcnow,
METH_NOARGS | METH_CLASS,
@@ -4412,7 +4420,7 @@
{"fromtimestamp", (PyCFunction)datetime_fromtimestamp,
METH_KEYWORDS | METH_CLASS,
- PyDoc_STR("timestamp[, tzinfo] -> local time from POSIX timestamp.")},
+ PyDoc_STR("timestamp[, tz] -> tz's local time from POSIX timestamp.")},
{"utcfromtimestamp", (PyCFunction)datetime_utcfromtimestamp,
METH_VARARGS | METH_CLASS,