summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2020-09-23 18:43:45 (GMT)
committerGitHub <noreply@github.com>2020-09-23 18:43:45 (GMT)
commit2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5 (patch)
tree7b8e1b98c94d77ffcdcfc61645c6b40f5ebd44ab /Modules
parent9c4eac7f02ddcf32fc1cdaf7c08c37fe9718c1fb (diff)
downloadcpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.zip
cpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.tar.gz
cpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.tar.bz2
bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)
Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO() macros.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c11
-rw-r--r--Modules/_testcapimodule.c6
-rw-r--r--Modules/_zoneinfo.c4
3 files changed, 8 insertions, 13 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 74a54e7..0631272 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -115,14 +115,9 @@ class datetime.IsoCalendarDate "PyDateTime_IsoCalendarDate *" "&PyDateTime_IsoCa
#define SET_TD_SECONDS(o, v) ((o)->seconds = (v))
#define SET_TD_MICROSECONDS(o, v) ((o)->microseconds = (v))
-/* p is a pointer to a time or a datetime object; HASTZINFO(p) returns
- * p->hastzinfo.
- */
-#define HASTZINFO(p) (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
-#define GET_TIME_TZINFO(p) (HASTZINFO(p) ? \
- ((PyDateTime_Time *)(p))->tzinfo : Py_None)
-#define GET_DT_TZINFO(p) (HASTZINFO(p) ? \
- ((PyDateTime_DateTime *)(p))->tzinfo : Py_None)
+#define HASTZINFO _PyDateTime_HAS_TZINFO
+#define GET_TIME_TZINFO PyDateTime_TIME_GET_TZINFO
+#define GET_DT_TZINFO PyDateTime_DATE_GET_TZINFO
/* M is a char or int claiming to be a valid month. The macro is equivalent
* to the two-sided Python test
* 1 <= M <= 12
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7536d29..0e09877 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2677,8 +2677,9 @@ test_PyDateTime_DATE_GET(PyObject *self, PyObject *obj)
minute = PyDateTime_DATE_GET_MINUTE(obj);
second = PyDateTime_DATE_GET_SECOND(obj);
microsecond = PyDateTime_DATE_GET_MICROSECOND(obj);
+ PyObject *tzinfo = PyDateTime_DATE_GET_TZINFO(obj);
- return Py_BuildValue("(llll)", hour, minute, second, microsecond);
+ return Py_BuildValue("(llllO)", hour, minute, second, microsecond, tzinfo);
}
static PyObject *
@@ -2690,8 +2691,9 @@ test_PyDateTime_TIME_GET(PyObject *self, PyObject *obj)
minute = PyDateTime_TIME_GET_MINUTE(obj);
second = PyDateTime_TIME_GET_SECOND(obj);
microsecond = PyDateTime_TIME_GET_MICROSECOND(obj);
+ PyObject *tzinfo = PyDateTime_TIME_GET_TZINFO(obj);
- return Py_BuildValue("(llll)", hour, minute, second, microsecond);
+ return Py_BuildValue("(llllO)", hour, minute, second, microsecond, tzinfo);
}
static PyObject *
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 2cee65f..bee59b8 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -484,9 +484,7 @@ zoneinfo_tzname(PyObject *self, PyObject *dt)
return tti->tzname;
}
-#define HASTZINFO(p) (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
-#define GET_DT_TZINFO(p) \
- (HASTZINFO(p) ? ((PyDateTime_DateTime *)(p))->tzinfo : Py_None)
+#define GET_DT_TZINFO PyDateTime_DATE_GET_TZINFO
static PyObject *
zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)