Commit 74d9df82 authored by Stefan Behnel's avatar Stefan Behnel

Make PyDateTime_DELTA_*() macros in datetime.pxd available in Py2.

See https://github.com/cython/cython/pull/3616
parent 6d83a741
......@@ -5,6 +5,17 @@ cdef extern from "Python.h":
pass
cdef extern from "datetime.h":
"""
#if PY_MAJOR_VERSION < 3 && !defined(PyDateTime_DELTA_GET_DAYS)
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyDateTime_DELTA_GET_SECONDS)
#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyDateTime_DELTA_GET_MICROSECONDS)
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
#endif
"""
ctypedef extern class datetime.date[object PyDateTime_Date]:
pass
......
......@@ -12,6 +12,13 @@ from cpython.datetime cimport date_day, date_month, date_year
from cpython.datetime cimport datetime_day, datetime_month, datetime_year
from cpython.datetime cimport datetime_hour, datetime_minute, datetime_second, \
datetime_microsecond
# These were added in Py3, make sure that their backport works.
from cpython.datetime cimport (
timedelta as timedelta_ext_type,
PyDateTime_DELTA_GET_DAYS,
PyDateTime_DELTA_GET_SECONDS,
PyDateTime_DELTA_GET_MICROSECONDS,
)
import datetime as py_datetime
......@@ -38,6 +45,22 @@ class FixedOffset(py_datetime.tzinfo):
def dst(self, dt):
return ZERO
def do_timedelta_macros(timedelta_ext_type delta):
"""
>>> delta = py_datetime.timedelta(days=13, hours=7, seconds=31, microseconds=993322)
>>> (delta.days, delta.seconds, delta.microseconds)
(13, 25231, 993322)
>>> do_timedelta_macros(delta)
(13, 25231, 993322)
"""
return (
PyDateTime_DELTA_GET_DAYS(delta),
PyDateTime_DELTA_GET_SECONDS(delta),
PyDateTime_DELTA_GET_MICROSECONDS(delta),
)
def do_date(int year, int month, int day):
"""
>>> do_date(2012, 12, 31)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment