Blob Blame History Raw
# HG changeset patch
# User Ronan Lamy <ronan.lamy@gmail.com>
# Date 1514473067 -3600
# Branch py3.5
# Node ID f145d85043878194d7eee33b2049063843e032d8
# Parent  d7d2710e65359e1e8d69e82612cb96f2f3921de7
Fix issue #2717

diff --git a/pypy/interpreter/test/test_timeutils.py b/pypy/interpreter/test/test_timeutils.py
new file mode 100644
index 0000000..873b2b4
--- /dev/null
+++ b/pypy/interpreter/test/test_timeutils.py
@@ -0,0 +1,13 @@
+import pytest
+from rpython.rlib.rarithmetic import r_longlong
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.timeutils import timestamp_w
+
+def test_timestamp_w(space):
+    w_1_year = space.newint(365 * 24 * 3600)
+    result = timestamp_w(space, w_1_year)
+    assert isinstance(result, r_longlong)
+    assert result // 10 ** 9 == space.int_w(w_1_year)
+    w_millenium = space.mul(w_1_year, space.newint(1000))
+    with pytest.raises(OperationError):  # timestamps overflow after ~300 years
+        timestamp_w(space, w_millenium)
diff --git a/pypy/interpreter/timeutils.py b/pypy/interpreter/timeutils.py
index 336426b..7918dc8 100644
--- a/pypy/interpreter/timeutils.py
+++ b/pypy/interpreter/timeutils.py
@@ -3,7 +3,7 @@ Access to the time module's high-resolution monotonic clock
 """
 import math
 from rpython.rlib.rarithmetic import (
-    r_longlong, ovfcheck, ovfcheck_float_to_longlong)
+    r_longlong, ovfcheck_float_to_longlong)
 from pypy.interpreter.error import oefmt
 
 SECS_TO_NS = 10 ** 9
@@ -28,10 +28,10 @@ def timestamp_w(space, w_secs):
             raise oefmt(space.w_OverflowError,
                 "timestamp %R too large to convert to C _PyTime_t", w_secs)
     else:
-        sec = space.int_w(w_secs)
         try:
-            result = ovfcheck(sec * SECS_TO_NS)
+            sec = space.bigint_w(w_secs).tolonglong()
+            result = sec * r_longlong(SECS_TO_NS)
         except OverflowError:
             raise oefmt(space.w_OverflowError,
-                "timestamp too large to convert to C _PyTime_t")
-        return r_longlong(result)
+                "timestamp %R too large to convert to C _PyTime_t", w_secs)
+        return result