summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2016-08-02 21:49:30 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2016-08-02 21:49:30 (GMT)
commit43746c37704861947179185b4c037e5f18f89a7c (patch)
tree3223ce1101db5f782c32888e83e64bae66290d09 /Modules/_datetimemodule.c
parent711120d8fd0445b33655101d72b0f576646bff9f (diff)
downloadcpython-43746c37704861947179185b4c037e5f18f89a7c.zip
cpython-43746c37704861947179185b4c037e5f18f89a7c.tar.gz
cpython-43746c37704861947179185b4c037e5f18f89a7c.tar.bz2
Closes #27661: Added tzinfo keyword argument to datetime.combine.
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 7dfb0c2..3048762 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -4430,28 +4430,32 @@ datetime_strptime(PyObject *cls, PyObject *args)
static PyObject *
datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
{
- static char *keywords[] = {"date", "time", NULL};
+ static char *keywords[] = {"date", "time", "tzinfo", NULL};
PyObject *date;
PyObject *time;
+ PyObject *tzinfo = NULL;
PyObject *result = NULL;
- if (PyArg_ParseTupleAndKeywords(args, kw, "O!O!:combine", keywords,
+ if (PyArg_ParseTupleAndKeywords(args, kw, "O!O!|O:combine", keywords,
&PyDateTime_DateType, &date,
- &PyDateTime_TimeType, &time)) {
- PyObject *tzinfo = Py_None;
-
- if (HASTZINFO(time))
- tzinfo = ((PyDateTime_Time *)time)->tzinfo;
+ &PyDateTime_TimeType, &time, &tzinfo)) {
+ if (tzinfo == NULL) {
+ if (HASTZINFO(time))
+ tzinfo = ((PyDateTime_Time *)time)->tzinfo;
+ else
+ tzinfo = Py_None;
+ }
result = PyObject_CallFunction(cls, "iiiiiiiO",
- GET_YEAR(date),
- GET_MONTH(date),
- GET_DAY(date),
- TIME_GET_HOUR(time),
- TIME_GET_MINUTE(time),
- TIME_GET_SECOND(time),
- TIME_GET_MICROSECOND(time),
- tzinfo);
- DATE_SET_FOLD(result, TIME_GET_FOLD(time));
+ GET_YEAR(date),
+ GET_MONTH(date),
+ GET_DAY(date),
+ TIME_GET_HOUR(time),
+ TIME_GET_MINUTE(time),
+ TIME_GET_SECOND(time),
+ TIME_GET_MICROSECOND(time),
+ tzinfo);
+ if (result)
+ DATE_SET_FOLD(result, TIME_GET_FOLD(time));
}
return result;
}