diff options
author | Georg Brandl <georg@python.org> | 2007-03-06 17:46:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-03-06 17:46:17 (GMT) |
commit | 02d7cffb8f0454e605401c05574b53321346fa46 (patch) | |
tree | 02728432ac475a5cff357ea18f8eaad789ca3fb8 /Modules | |
parent | 1a74b4325cdfac112bf0d4df8559f87ad3cb9f1a (diff) | |
download | cpython-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.c | 6 |
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. */ |