summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-23 20:53:10 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-23 20:53:10 (GMT)
commit2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c (patch)
tree7ac5d610e87d7a2b56e097e14525d9bc3182459f /Modules/datetimemodule.c
parent10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d (diff)
downloadcpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.zip
cpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.tar.gz
cpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.tar.bz2
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.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c32
1 files changed, 20 insertions, 12 deletions
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 @@ datetime_now(PyObject *cls, PyObject *args, PyObject *kw)
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 @@ datetime_utcnow(PyObject *cls, PyObject *dummy)
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, &timestamp, &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, &timestamp, &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 @@ static PyMethodDef datetime_methods[] = {
{"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 @@ static PyMethodDef datetime_methods[] = {
{"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,