Commits

Armin Rigo committed 3f834e4

Support (reasonably) converting a user-supplied "double" directly to a
time_t, which may be 64-bit even on 32-bit platforms --- notably on
Windows. Should fix issue1697.

Comments (0)

Files changed (2)

pypy/module/rctime/interp_time.py

         seconds = pytime.time()
     else:
         seconds = space.float_w(w_seconds)
-    try:
-        seconds = ovfcheck_float_to_int(seconds)
-        t = rffi.r_time_t(seconds)
-        if rffi.cast(lltype.Signed, t) != seconds:
-            raise OverflowError
-    except OverflowError:
+    #
+    t = rffi.cast(rffi.TIME_T, seconds)
+    #
+    # Logic from CPython: How much info did we lose?  We assume that
+    # time_t is an integral type.  If we lost a second or more, the
+    # input doesn't fit in a time_t; call it an error.
+    diff = seconds - rffi.cast(lltype.Float, t)
+    if diff <= -1.0 or diff >= 1.0:
         raise OperationError(space.w_ValueError,
-                             space.wrap("time argument too large"))
+                      space.wrap("timestamp out of range for platform time_t"))
     return t
 
 def _tm_to_tuple(space, t):

pypy/module/rctime/test/test_rctime.py

         assert 0 <= (t1 - t0) < 1.2
         t = rctime.time()
         assert rctime.gmtime(t) == rctime.gmtime(t)
+        raises(ValueError, rctime.gmtime, 2**64)
+        raises(ValueError, rctime.gmtime, -2**64)
 
     def test_localtime(self):
         import time as rctime