summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-03-06 15:50:01 (GMT)
committerGuido van Rossum <guido@python.org>2007-03-06 15:50:01 (GMT)
commit2054ee9b6f268d16e90e4ff30186b5a4a1f91719 (patch)
tree031cec2752a201c6f5b4d4139781f6f7dc38394c /Modules/datetimemodule.c
parentd1287323ca3273f4408a5c3f3047c316b72ea78c (diff)
downloadcpython-2054ee9b6f268d16e90e4ff30186b5a4a1f91719.zip
cpython-2054ee9b6f268d16e90e4ff30186b5a4a1f91719.tar.gz
cpython-2054ee9b6f268d16e90e4ff30186b5a4a1f91719.tar.bz2
Patch #1646728: datetime.fromtimestamp fails with negative
fractional times. With unittest. Somebody please backport to 2.5.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index cf8a68b..7487c50 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -3683,6 +3683,12 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, double timestamp,
return NULL;
fraction = timestamp - (double)timet;
us = (int)round_to_long(fraction * 1e6);
+ if (us < 0) {
+ /* Truncation towards zero is not what we wanted
+ for negative numbers (Python's mod semantics) */
+ timet -= 1;
+ us += 1000000;
+ }
/* If timestamp is less than one microsecond smaller than a
* full second, round up. Otherwise, ValueErrors are raised
* for some floats. */