summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-23 19:58:02 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-23 19:58:02 (GMT)
commit10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d (patch)
treea08fd27ddaa04db1b7cad9c552b08fd964e53a68 /Modules/datetimemodule.c
parent250684ddd8223de98b5944d13e89a12673d0a51a (diff)
downloadcpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.zip
cpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.tar.gz
cpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.tar.bz2
Reimplemented datetime.now() to be useful.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index f615f68..d81d563 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -3666,15 +3666,25 @@ datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
static PyObject *
datetime_now(PyObject *cls, PyObject *args, PyObject *kw)
{
- PyObject *self = NULL;
+ PyObject *self;
PyObject *tzinfo = Py_None;
- static char *keywords[] = {"tzinfo", NULL};
+ static char *keywords[] = {"tz", NULL};
- if (PyArg_ParseTupleAndKeywords(args, kw, "|O:now", keywords,
- &tzinfo)) {
- if (check_tzinfo_subclass(tzinfo) < 0)
- return NULL;
- self = datetime_best_possible(cls, localtime, tzinfo);
+ if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:now", keywords,
+ &tzinfo))
+ return NULL;
+ if (check_tzinfo_subclass(tzinfo) < 0)
+ return NULL;
+
+ self = datetime_best_possible(cls,
+ tzinfo == Py_None ? localtime : gmtime,
+ 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;
}