Reimplemented datetime.now() to be useful.
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 @@
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;
}