# HG changeset patch
# User Kevin Gessner <kevin@fogcreek.com>
# Date 1316793747 25200
#      Fri Sep 23 09:02:27 2011 -0700
# Branch stable
# Node ID c208dcd0f70957ce871fdacbf8d1432021de79b5
# Parent  94b200a11cf7adfee75bb865d238a077ee75b79c
util: fix crash converting an invalid future date to string

Post-2038 timestamps cannot be handled on 32-bit architectures. Clamp
such dates to the maximum 32-bit timestamp.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -891,7 +891,12 @@
         minutes = abs(tz) // 60
         format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
         format = format.replace("%2", "%02d" % (minutes % 60))
-    s = time.strftime(format, time.gmtime(float(t) - tz))
+    try:
+        t = time.gmtime(float(t) - tz)
+    except ValueError:
+        # time was out of range
+        t = time.gmtime(sys.maxint)
+    s = time.strftime(format, t)
     return s
 
 def shortdate(date=None):