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
cbe43273
Commit
cbe43273
authored
May 19, 2020
by
jbrockmendel
Committed by
GitHub
May 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide timedelta.total_seconds() implementation in datetime.pxd (GH-3616)
parent
74d9df82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
Cython/Includes/cpython/datetime.pxd
Cython/Includes/cpython/datetime.pxd
+11
-0
tests/run/datetime_pxd.pyx
tests/run/datetime_pxd.pyx
+19
-1
No files found.
Cython/Includes/cpython/datetime.pxd
View file @
cbe43273
...
...
@@ -221,3 +221,14 @@ cdef inline int timedelta_seconds(object o):
# Get microseconds of timedelta
cdef
inline
int
timedelta_microseconds
(
object
o
):
return
(
<
PyDateTime_Delta
*>
o
).
microseconds
cdef
inline
double
total_seconds
(
timedelta
obj
):
# Mirrors the "timedelta.total_seconds()" method.
# Note that this implementation is not guaranteed to give *exactly* the same
# result as the original method, due to potential differences in floating point rounding.
cdef
:
double
days
,
seconds
,
micros
days
=
<
double
>
PyDateTime_DELTA_GET_DAYS
(
obj
)
seconds
=
<
double
>
PyDateTime_DELTA_GET_SECONDS
(
obj
)
micros
=
<
double
>
PyDateTime_DELTA_GET_MICROSECONDS
(
obj
)
return
days
*
24
*
3600
+
seconds
+
micros
/
1_000_000
tests/run/datetime_pxd.pyx
View file @
cbe43273
...
...
@@ -4,7 +4,7 @@
#from datetime import time, date, datetime, timedelta, tzinfo
from
cpython.datetime
cimport
import_datetime
from
cpython.datetime
cimport
import_datetime
,
timedelta
from
cpython.datetime
cimport
time_new
,
date_new
,
datetime_new
,
timedelta_new
from
cpython.datetime
cimport
time_tzinfo
,
datetime_tzinfo
from
cpython.datetime
cimport
time_hour
,
time_minute
,
time_second
,
time_microsecond
...
...
@@ -12,6 +12,8 @@ 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
from
cpython.datetime
cimport
datetime
,
total_seconds
# These were added in Py3, make sure that their backport works.
from
cpython.datetime
cimport
(
timedelta
as
timedelta_ext_type
,
...
...
@@ -194,3 +196,19 @@ def do_datetime_tzinfo2(int year, int month, int day,
r7
=
(
v2
==
v
)
r8
=
(
v3
==
v1
)
return
r1
,
r2
,
r3
,
r4
,
r5
,
r6
,
r7
,
r8
def
test_timedelta_total_seconds
():
"""
>>> cytotal, pytotal = test_timedelta_total_seconds()
>>> assert cytotal == pytotal, (cytotal, pytotal)
>>> cytotal == pytotal
True
"""
cdef
:
datetime
now
=
py_datetime
.
datetime
.
now
()
timedelta
td
=
now
-
py_datetime
.
datetime
(
1970
,
1
,
1
)
pytd
=
now
-
py_datetime
.
datetime
(
1970
,
1
,
1
)
return
total_seconds
(
td
),
pytd
.
total_seconds
()
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