Patch #1646728: datetime.fromtimestamp fails with negative
fractional times.  With unittest.
  (backport from rev. 54167 by Guido)
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 @@
 		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. */