Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ff7f428b
Commit
ff7f428b
authored
Mar 27, 2015
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
781692ff
992c43fe
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
211 additions
and
86 deletions
+211
-86
Include/pytime.h
Include/pytime.h
+6
-3
Lib/test/test_time.py
Lib/test/test_time.py
+173
-79
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+17
-0
Modules/timemodule.c
Modules/timemodule.c
+1
-1
Python/pytime.c
Python/pytime.c
+14
-3
No files found.
Include/pytime.h
View file @
ff7f428b
...
...
@@ -121,15 +121,18 @@ typedef PY_INT64_T _PyTime_t;
/* Convert a Python float or int to a timetamp.
Raise an exception and return -1 on error, return 0 on success. */
PyAPI_FUNC
(
int
)
_PyTime_FromObject
(
_PyTime_t
*
t
,
PyAPI_FUNC
(
int
)
_PyTime_From
Seconds
Object
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
);
/* Convert timestamp to a number of milliseconds (10^-3 seconds). */
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_AsMilliseconds
(
_PyTime_t
t
,
PyAPI_FUNC
(
_PyTime_t
)
_PyTime_AsMilliseconds
(
_PyTime_t
t
,
_PyTime_round_t
round
);
/* Convert timestamp to a number of nanoseconds (10^-9 seconds) as a Python int
object. */
PyAPI_FUNC
(
PyObject
*
)
_PyTime_AsNanosecondsObject
(
_PyTime_t
t
);
/* Convert a timestamp to a timeval structure. */
PyAPI_FUNC
(
int
)
_PyTime_AsTimeval
(
_PyTime_t
t
,
struct
timeval
*
tv
,
...
...
Lib/test/test_time.py
View file @
ff7f428b
This diff is collapsed.
Click to expand it.
Modules/_testcapimodule.c
View file @
ff7f428b
...
...
@@ -3378,6 +3378,22 @@ return_result_with_error(PyObject *self, PyObject *args)
Py_RETURN_NONE
;
}
static
PyObject
*
test_pytime_fromsecondsobject
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
obj
;
int
round
;
_PyTime_t
ts
;
if
(
!
PyArg_ParseTuple
(
args
,
"Oi"
,
&
obj
,
&
round
))
return
NULL
;
if
(
check_time_rounding
(
round
)
<
0
)
return
NULL
;
if
(
_PyTime_FromSecondsObject
(
&
ts
,
obj
,
round
)
==
-
1
)
return
NULL
;
return
_PyTime_AsNanosecondsObject
(
ts
);
}
static
PyMethodDef
TestMethods
[]
=
{
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
...
...
@@ -3541,6 +3557,7 @@ static PyMethodDef TestMethods[] = {
return_null_without_error
,
METH_NOARGS
},
{
"return_result_with_error"
,
return_result_with_error
,
METH_NOARGS
},
{
"pytime_fromsecondsobject"
,
test_pytime_fromsecondsobject
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
Modules/timemodule.c
View file @
ff7f428b
...
...
@@ -221,7 +221,7 @@ static PyObject *
time_sleep
(
PyObject
*
self
,
PyObject
*
obj
)
{
_PyTime_t
secs
;
if
(
_PyTime_FromObject
(
&
secs
,
obj
,
_PyTime_ROUND_UP
))
if
(
_PyTime_From
Seconds
Object
(
&
secs
,
obj
,
_PyTime_ROUND_UP
))
return
NULL
;
if
(
secs
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
...
...
Python/pytime.c
View file @
ff7f428b
...
...
@@ -424,7 +424,7 @@ _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts)
#endif
int
_PyTime_FromObject
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
)
_PyTime_From
Seconds
Object
(
_PyTime_t
*
t
,
PyObject
*
obj
,
_PyTime_round_t
round
)
{
if
(
PyFloat_Check
(
obj
))
{
double
d
,
err
;
...
...
@@ -433,8 +433,7 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
d
=
PyFloat_AsDouble
(
obj
);
d
*=
1e9
;
/* FIXME: use sign */
if
(
round
==
_PyTime_ROUND_UP
)
if
((
round
==
_PyTime_ROUND_UP
)
^
(
d
<
0
))
d
=
ceil
(
d
);
else
d
=
floor
(
d
);
...
...
@@ -471,6 +470,18 @@ _PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round)
}
}
PyObject
*
_PyTime_AsNanosecondsObject
(
_PyTime_t
t
)
{
#ifdef HAVE_LONG_LONG
assert
(
sizeof
(
PY_LONG_LONG
)
>=
sizeof
(
_PyTime_t
));
return
PyLong_FromLongLong
((
PY_LONG_LONG
)
t
);
#else
assert
(
sizeof
(
long
)
>=
sizeof
(
_PyTime_t
));
return
PyLong_FromLong
((
long
)
t
);
#endif
}
static
_PyTime_t
_PyTime_Multiply
(
_PyTime_t
t
,
unsigned
int
multiply
,
_PyTime_round_t
round
)
{
...
...
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