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
14559510
Commit
14559510
authored
May 02, 2021
by
Bluenix
Committed by
GitHub
May 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing declarations to datetime.pxd (GH-4128)
parent
1b98f7b1
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
261 additions
and
38 deletions
+261
-38
Cython/Includes/cpython/datetime.pxd
Cython/Includes/cpython/datetime.pxd
+173
-21
tests/run/datetime_cimport.pyx
tests/run/datetime_cimport.pyx
+21
-2
tests/run/datetime_members.pyx
tests/run/datetime_members.pyx
+27
-14
tests/run/datetime_pxd.pyx
tests/run/datetime_pxd.pyx
+40
-1
No files found.
Cython/Includes/cpython/datetime.pxd
View file @
14559510
This diff is collapsed.
Click to expand it.
tests/run/datetime_cimport.pyx
View file @
14559510
# coding: utf-8
from
cpython.datetime
cimport
import_datetime
from
cpython.datetime
cimport
date
,
time
,
datetime
,
timedelta
,
PyDateTime_IMPORT
from
cpython.datetime
cimport
date
,
time
,
datetime
,
timedelta
,
timezone_new
,
PyDateTime_IMPORT
import
sys
import_datetime
()
def
test_date
(
int
year
,
int
month
,
int
day
):
'''
>>> val = test_date(2012, 12, 31)
...
...
@@ -40,3 +42,20 @@ def test_timedelta(int days, int seconds, int useconds):
'''
val
=
timedelta
(
days
,
seconds
,
useconds
)
return
val
def
test_timezone
(
int
days
,
int
seconds
,
int
useconds
,
str
name
):
'''
>>> val = test_timezone(0, 3600, 0, 'CET')
>>> print(val)
True
'''
try
:
val
=
timezone_new
(
timedelta
(
days
,
seconds
,
useconds
),
name
)
except
RuntimeError
:
if
sys
.
version_info
<
(
3
,
7
):
return
True
else
:
# It's only supposed to raise on Python < 3.7
return
False
else
:
return
True
tests/run/datetime_members.pyx
View file @
14559510
# mode: run
# tag: datetime
import
sys
from
cpython.datetime
cimport
import_datetime
from
cpython.datetime
cimport
time_new
,
date_new
,
datetime_new
,
timedelta_new
from
cpython.datetime
cimport
datetime
,
time
from
cpython.datetime
cimport
time_tzinfo
,
datetime_tzinfo
from
cpython.datetime
cimport
time_hour
,
time_minute
,
time_second
,
time_microsecond
from
cpython.datetime
cimport
time_hour
,
time_minute
,
time_second
,
time_microsecond
,
time_fold
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
datetime_microsecond
,
datetime_fold
from
cpython.datetime
cimport
timedelta_days
,
timedelta_seconds
,
timedelta_microseconds
import_datetime
()
...
...
@@ -20,31 +26,39 @@ def test_date(int year, int month, int day):
o
.
month
==
date_month
(
o
),
\
o
.
day
==
date_day
(
o
)
def
test_datetime
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
microsecon
d
):
def
test_datetime
(
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
int
fol
d
):
'''
>>> test_datetime(2012, 12, 31, 12, 30, 59, 12345)
(True, True, True, True, True, True, True)
>>> test_datetime(2012, 12, 31, 12, 30, 59, 12345, 0)
(True, True, True, True, True, True, True, True)
>>> test_datetime(2012, 12, 11, 12, 30, 59, 3322, 1 if sys.version_info >= (3, 7) else 0)
(True, True, True, True, True, True, True, True)
'''
o
=
datetime_new
(
year
,
month
,
day
,
hour
,
minute
,
second
,
microsecond
,
None
)
o
=
datetime_new
(
year
,
month
,
day
,
hour
,
minute
,
second
,
microsecond
,
None
,
fold
)
return
o
.
year
==
datetime_year
(
o
),
\
o
.
month
==
datetime_month
(
o
),
\
o
.
day
==
datetime_day
(
o
),
\
o
.
hour
==
datetime_hour
(
o
),
\
o
.
minute
==
datetime_minute
(
o
),
\
o
.
second
==
datetime_second
(
o
),
\
o
.
microsecond
==
datetime_microsecond
(
o
)
o
.
microsecond
==
datetime_microsecond
(
o
),
\
o
.
fold
==
datetime_fold
(
o
)
def
test_time
(
int
hour
,
int
minute
,
int
second
,
int
microsecond
):
def
test_time
(
int
hour
,
int
minute
,
int
second
,
int
microsecond
,
int
fold
):
'''
>>> test_time(12, 30, 59, 12345)
(True, True, True, True)
>>> test_time(12, 30, 59, 12345, 0)
(True, True, True, True, True)
>>> test_time(12, 30, 43, 5432, 1 if sys.version_info >= (3, 7) else 0)
(True, True, True, True, True)
'''
o
=
time_new
(
hour
,
minute
,
second
,
microsecond
,
None
)
o
=
time_new
(
hour
,
minute
,
second
,
microsecond
,
None
,
fold
)
return
o
.
hour
==
time_hour
(
o
),
\
o
.
minute
==
time_minute
(
o
),
\
o
.
second
==
time_second
(
o
),
\
o
.
microsecond
==
time_microsecond
(
o
)
o
.
microsecond
==
time_microsecond
(
o
),
\
o
.
fold
==
time_fold
(
o
)
def
test_timedelta
(
int
days
,
int
seconds
,
int
microseconds
):
'''
...
...
@@ -55,4 +69,3 @@ def test_timedelta(int days, int seconds, int microseconds):
return
o
.
days
==
timedelta_days
(
o
),
\
o
.
seconds
==
timedelta_seconds
(
o
),
\
o
.
microseconds
==
timedelta_microseconds
(
o
)
tests/run/datetime_pxd.pyx
View file @
14559510
...
...
@@ -11,8 +11,9 @@ from cpython.datetime cimport datetime_day, datetime_month, datetime_year
from
cpython.datetime
cimport
datetime_hour
,
datetime_minute
,
datetime_second
,
\
datetime_microsecond
from
cpython.datetime
cimport
datetime
,
total_seconds
from
cpython.datetime
cimport
date_from_timestamp
,
get_utc
,
datetime_from_timestamp
# These were added in Py
3
, make sure that their backport works.
# These were added in Py
thon 2.7.5
, make sure that their backport works.
from
cpython.datetime
cimport
(
timedelta
as
timedelta_ext_type
,
PyDateTime_DELTA_GET_DAYS
,
...
...
@@ -21,6 +22,8 @@ from cpython.datetime cimport (
)
import
datetime
as
py_datetime
import
time
as
py_time
import
sys
import_datetime
()
...
...
@@ -238,3 +241,39 @@ def test_datetime_attrs_inlined(datetime dt):
dt
.
second
,
dt
.
microsecond
,
)
def
test_date_from_timestamp
():
"""
>>> from datetime import datetime
>>> tp, dt = test_date_from_timestamp()
>>> tp == dt
True
"""
tp
=
date_from_timestamp
(
1518185542
)
dt
=
py_datetime
.
date
(
2018
,
2
,
9
)
return
tp
,
dt
def
test_get_utc
():
"""
>>> from datetime import datetime
>>> test_get_utc()
True
"""
try
:
get_utc
()
except
RuntimeError
:
if
sys
.
version_info
>=
(
3
,
7
):
raise
# get_utc() is only supposed to raise on Python < 3.7
return
True
def
test_datetime_from_timestamp
():
"""
>>> from datetime import datetime
>>> tp, dt = test_datetime_from_timestamp()
>>> tp == dt
True
"""
time
=
py_time
.
time
()
tp
=
datetime_from_timestamp
(
time
)
dt
=
py_datetime
.
datetime
.
fromtimestamp
(
time
)
return
tp
,
dt
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