[PATCH 2 of 2 v2] Allow commit date before Unix epoch, clean fix for (issue2513)

Florent Gallaire fgallaire at gmail.com
Fri Apr 1 21:00:26 EDT 2016


# HG changeset patch
# User Florent Gallaire <fgallaire at gmail.com>
# Date 1459558097 -7200
#      Sat Apr 02 02:48:17 2016 +0200
# Node ID 444c0e7bb41269fb8c684a66454610d291929738
# Parent  8152e614ee77606b3e26f8935ded4157b4caa86c
date: clean fix for Windows buggy gmtime() (issue2513)

diff -r 8152e614ee77 -r 444c0e7bb412 mercurial/util.py
--- a/mercurial/util.py    Tue Mar 29 02:50:16 2016 +0200
+++ b/mercurial/util.py    Sat Apr 02 02:48:17 2016 +0200
@@ -1586,11 +1586,12 @@
         format = format.replace("%1", "%c%02d" % (sign, q))
         format = format.replace("%2", "%02d" % r)
     try:
-        t = time.gmtime(float(t) - tz)
-    except ValueError:
+        t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=t - tz)
+    except OverflowError:
         # time was out of range
-        t = time.gmtime(sys.maxint)
-    s = time.strftime(format, t)
+        t = (datetime.datetime(1970, 1, 1) +
+             datetime.timedelta(seconds=cmp(t, 0) * 0x7fffffff))
+    s = t.strftime(format)
     return s

 def shortdate(date=None):


More information about the Mercurial-devel mailing list