Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
74d9df82
Commit
74d9df82
authored
May 19, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make PyDateTime_DELTA_*() macros in datetime.pxd available in Py2.
See
https://github.com/cython/cython/pull/3616
parent
6d83a741
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
41 deletions
+75
-41
Cython/Includes/cpython/datetime.pxd
Cython/Includes/cpython/datetime.pxd
+11
-0
tests/run/datetime_pxd.pyx
tests/run/datetime_pxd.pyx
+64
-41
No files found.
Cython/Includes/cpython/datetime.pxd
View file @
74d9df82
...
...
@@ -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
...
...
tests/run/datetime_pxd.pyx
View file @
74d9df82
...
...
@@ -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
...
...
@@ -37,7 +44,23 @@ 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)
...
...
@@ -46,7 +69,7 @@ def do_date(int year, int month, int day):
v
=
date_new
(
year
,
month
,
day
)
return
type
(
v
)
is
py_datetime
.
date
,
v
.
year
==
year
,
v
.
month
==
month
,
v
.
day
==
day
def
do_datetime
(
int
year
,
int
month
,
int
day
,
def
do_datetime
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
microsecond
):
"""
>>> do_datetime(2012, 12, 31, 12, 23, 0, 0)
...
...
@@ -69,7 +92,7 @@ def do_time(int hour, int minute, int second, int microsecond):
def
do_time_tzinfo
(
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
object
tz
):
"""
>>> tz = FixedOffset(60*3, 'Moscow')
>>> tz = FixedOffset(60*3, 'Moscow')
>>> do_time_tzinfo(12, 23, 0, 0, tz)
(True, True, True, True, True, True)
"""
...
...
@@ -79,10 +102,10 @@ def do_time_tzinfo(int hour, int minute, int second, int microsecond, object tz)
v
.
microsecond
==
microsecond
,
v
.
tzinfo
is
tz
def
do_datetime_tzinfo
(
int
year
,
int
month
,
int
day
,
def
do_datetime_tzinfo
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
object
tz
):
"""
>>> tz = FixedOffset(60*3, 'Moscow')
>>> tz = FixedOffset(60*3, 'Moscow')
>>> do_datetime_tzinfo(2012, 12, 31, 12, 23, 0, 0, tz)
(True, True, True, True, True, True, True, True, True)
"""
...
...
@@ -90,35 +113,35 @@ def do_datetime_tzinfo(int year, int month, int day,
return
type
(
v
)
is
py_datetime
.
datetime
,
v
.
year
==
year
,
v
.
month
==
month
,
v
.
day
==
day
,
\
v
.
hour
==
hour
,
v
.
minute
==
minute
,
v
.
second
==
second
,
\
v
.
microsecond
==
microsecond
,
v
.
tzinfo
is
tz
def
do_time_tzinfo2
(
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
object
tz
):
"""
>>> tz = FixedOffset(60*3, 'Moscow')
>>> tz = FixedOffset(60*3, 'Moscow')
>>> do_time_tzinfo2(12, 23, 0, 0, tz)
(True, True, True, True, True, True, True, True)
"""
v
=
time_new
(
hour
,
minute
,
second
,
microsecond
,
None
)
v1
=
time_new
(
time_hour
(
v
),
time_minute
(
v
),
time_second
(
v
),
time_microsecond
(
v
),
time_hour
(
v
),
time_minute
(
v
),
time_second
(
v
),
time_microsecond
(
v
),
tz
)
r1
=
(
v1
.
tzinfo
==
tz
)
r2
=
(
tz
==
time_tzinfo
(
v1
))
v2
=
time_new
(
time_hour
(
v1
),
time_minute
(
v1
),
time_second
(
v1
),
time_microsecond
(
v1
),
time_hour
(
v1
),
time_minute
(
v1
),
time_second
(
v1
),
time_microsecond
(
v1
),
None
)
r3
=
(
v2
.
tzinfo
==
None
)
r4
=
(
None
==
time_tzinfo
(
v2
))
v3
=
time_new
(
time_hour
(
v2
),
time_minute
(
v2
),
time_second
(
v2
),
time_microsecond
(
v2
),
time_hour
(
v2
),
time_minute
(
v2
),
time_second
(
v2
),
time_microsecond
(
v2
),
tz
)
r5
=
(
v3
.
tzinfo
==
tz
)
r6
=
(
tz
==
time_tzinfo
(
v3
))
...
...
@@ -130,41 +153,41 @@ def do_time_tzinfo2(int hour, int minute, int second, int microsecond, object tz
def
do_datetime_tzinfo2
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
object
tz
):
"""
>>> tz = FixedOffset(60*3, 'Moscow')
>>> tz = FixedOffset(60*3, 'Moscow')
>>> do_datetime_tzinfo2(2012, 12, 31, 12, 23, 0, 0, tz)
(True, True, True, True, True, True, True, True)
"""
v
=
datetime_new
(
year
,
month
,
day
,
hour
,
minute
,
second
,
microsecond
,
None
)
v1
=
datetime_new
(
datetime_year
(
v
),
datetime_month
(
v
),
datetime_day
(
v
),
datetime_hour
(
v
),
datetime_minute
(
v
),
datetime_second
(
v
),
datetime_microsecond
(
v
),
datetime_year
(
v
),
datetime_month
(
v
),
datetime_day
(
v
),
datetime_hour
(
v
),
datetime_minute
(
v
),
datetime_second
(
v
),
datetime_microsecond
(
v
),
tz
)
r1
=
(
v1
.
tzinfo
==
tz
)
r2
=
(
tz
==
datetime_tzinfo
(
v1
))
v2
=
datetime_new
(
datetime_year
(
v1
),
datetime_month
(
v1
),
datetime_day
(
v1
),
datetime_hour
(
v1
),
datetime_minute
(
v1
),
datetime_second
(
v1
),
datetime_microsecond
(
v1
),
datetime_year
(
v1
),
datetime_month
(
v1
),
datetime_day
(
v1
),
datetime_hour
(
v1
),
datetime_minute
(
v1
),
datetime_second
(
v1
),
datetime_microsecond
(
v1
),
None
)
r3
=
(
v2
.
tzinfo
==
None
)
r4
=
(
None
==
datetime_tzinfo
(
v2
))
v3
=
datetime_new
(
datetime_year
(
v2
),
datetime_month
(
v2
),
datetime_day
(
v2
),
datetime_hour
(
v2
),
datetime_minute
(
v2
),
datetime_second
(
v2
),
datetime_microsecond
(
v2
),
datetime_year
(
v2
),
datetime_month
(
v2
),
datetime_day
(
v2
),
datetime_hour
(
v2
),
datetime_minute
(
v2
),
datetime_second
(
v2
),
datetime_microsecond
(
v2
),
tz
)
r5
=
(
v3
.
tzinfo
==
tz
)
r6
=
(
tz
==
datetime_tzinfo
(
v3
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment