summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-04-28 19:09:24 (GMT)
committerGeorg Brandl <georg@python.org>2006-04-28 19:09:24 (GMT)
commit6d78a582ec2e24d3ec4d449b0960613b17c602e2 (patch)
tree14198ca21f249d0ec91702504a326831d451ed20 /Modules
parent6a907d8b8ef4ebe86730386f2c1ff788bc8b945f (diff)
downloadcpython-6d78a582ec2e24d3ec4d449b0960613b17c602e2.zip
cpython-6d78a582ec2e24d3ec4d449b0960613b17c602e2.tar.gz
cpython-6d78a582ec2e24d3ec4d449b0960613b17c602e2.tar.bz2
Bug #1478429: make datetime.datetime.fromtimestamp accept every float,
possibly "rounding up" to the next whole second.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index b7bddff..648ebe5 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -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);
}