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
6d78a582
Commit
6d78a582
authored
Apr 28, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1478429: make datetime.datetime.fromtimestamp accept every float,
possibly "rounding up" to the next whole second.
parent
6a907d8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
Lib/test/test_datetime.py
Lib/test/test_datetime.py
+6
-0
Modules/datetimemodule.c
Modules/datetimemodule.c
+7
-0
No files found.
Lib/test/test_datetime.py
View file @
6d78a582
...
...
@@ -1400,6 +1400,12 @@ class TestDateTime(TestDate):
got
=
self
.
theclass
.
utcfromtimestamp
(
ts
)
self
.
verify_field_equality
(
expected
,
got
)
def
test_microsecond_rounding
(
self
):
# Test whether fromtimestamp "rounds up" floats that are less
# than one microsecond smaller than an integer.
self
.
assertEquals
(
self
.
theclass
.
fromtimestamp
(
0.9999999
),
self
.
theclass
.
fromtimestamp
(
1
))
def
test_insane_fromtimestamp
(
self
):
# It's possible that some platform maps time_t to double,
# and that this test will fail there. This test should
...
...
Modules/datetimemodule.c
View file @
6d78a582
...
...
@@ -3683,6 +3683,13 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, double timestamp,
return
NULL
;
fraction
=
timestamp
-
(
double
)
timet
;
us
=
(
int
)
round_to_long
(
fraction
*
1e6
);
/* If timestamp is less than one microsecond smaller than a
* full second, round up. Otherwise, ValueErrors are raised
* for some floats. */
if
(
us
==
1000000
)
{
timet
+=
1
;
us
=
0
;
}
return
datetime_from_timet_and_us
(
cls
,
f
,
timet
,
us
,
tzinfo
);
}
...
...
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