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
a8d806be
Commit
a8d806be
authored
Nov 07, 2020
by
jbrockmendel
Committed by
GitHub
Nov 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: C-properties for datetime objects (GH-3737)
parent
3774a78b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
Cython/Includes/cpython/datetime.pxd
Cython/Includes/cpython/datetime.pxd
+27
-1
tests/run/datetime_pxd.pyx
tests/run/datetime_pxd.pyx
+29
-3
No files found.
Cython/Includes/cpython/datetime.pxd
View file @
a8d806be
...
...
@@ -24,7 +24,33 @@ cdef extern from "datetime.h":
pass
ctypedef
extern
class
datetime
.
datetime
[
object
PyDateTime_DateTime
]:
pass
@
property
cdef
inline
int
year
(
self
):
return
PyDateTime_GET_YEAR
(
self
)
@
property
cdef
inline
int
month
(
self
):
return
PyDateTime_GET_MONTH
(
self
)
@
property
cdef
inline
int
day
(
self
):
return
PyDateTime_GET_DAY
(
self
)
@
property
cdef
inline
int
hour
(
self
):
return
PyDateTime_DATE_GET_HOUR
(
self
)
@
property
cdef
inline
int
minute
(
self
):
return
PyDateTime_DATE_GET_MINUTE
(
self
)
@
property
cdef
inline
int
second
(
self
):
return
PyDateTime_DATE_GET_SECOND
(
self
)
@
property
cdef
inline
int
microsecond
(
self
):
return
PyDateTime_DATE_GET_MICROSECOND
(
self
)
ctypedef
extern
class
datetime
.
timedelta
[
object
PyDateTime_Delta
]:
pass
...
...
tests/run/datetime_pxd.pyx
View file @
a8d806be
# coding: utf-8
#cimport cpython.datetime as cy_datetime
#from datetime import time, date, datetime, timedelta, tzinfo
cimport
cython
from
cpython.datetime
cimport
import_datetime
,
timedelta
from
cpython.datetime
cimport
time_new
,
date_new
,
datetime_new
,
timedelta_new
...
...
@@ -212,3 +210,31 @@ def test_timedelta_total_seconds():
pytd
=
now
-
py_datetime
.
datetime
(
1970
,
1
,
1
)
return
total_seconds
(
td
),
pytd
.
total_seconds
()
@
cython
.
test_fail_if_path_exists
(
"//CoerceFromPyTypeNode"
,
"//AttributeNode"
,
)
def
test_datetime_attrs_inlined
(
datetime
dt
):
# GH#3737
"""
>>> from datetime import datetime
>>> py_dt = datetime(2020, 8, 18, 4, 9)
>>> dt = test_datetime_attrs_inlined(py_dt)
>>> dt[:5]
(2020, 8, 18, 4, 9)
>>> dt[5] == py_dt.second or (dt[5], py_dt.second)
True
>>> dt[6] == py_dt.microsecond or (dt[6], py_dt.microsecond)
True
"""
return
(
dt
.
year
,
dt
.
month
,
dt
.
day
,
dt
.
hour
,
dt
.
minute
,
dt
.
second
,
dt
.
microsecond
,
)
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