summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-06 17:46:17 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-06 17:46:17 (GMT)
commit02d7cffb8f0454e605401c05574b53321346fa46 (patch)
tree02728432ac475a5cff357ea18f8eaad789ca3fb8 /Modules
parent1a74b4325cdfac112bf0d4df8559f87ad3cb9f1a (diff)
downloadcpython-02d7cffb8f0454e605401c05574b53321346fa46.zip
cpython-02d7cffb8f0454e605401c05574b53321346fa46.tar.gz
cpython-02d7cffb8f0454e605401c05574b53321346fa46.tar.bz2
Patch #1646728: datetime.fromtimestamp fails with negative
fractional times. With unittest. (backport from rev. 54167 by Guido)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 9ae7732..8207ffd 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -3686,6 +3686,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. */