Mercurial > hg > mercurial-crew
comparison mercurial/util.py @ 13039:dd24f3e7ca9e stable
util.datestr: do not crash on revisions with negative timestamp (issue2513)
Python's time.gmtime(lt) fails on Windows, producing a traceback with
ValueError: (22, 'Invalid argument')
if lt < -43200.
We get a local time boundary value of -43200 if we take "the epoch"
Thu Jan 01 00:00:00 1970 = time.gmtime(0)
from timezone 'UTC+0' into timezone 'UTC-12'. All other timezones will have
larger local time values for that point in time.
Aborting with a traceback on 'hg log' for revisions with a timestamp value
< -43200 is clearly not acceptable.
Returning "invalid timestamp" or similar as string representation is not an
option either, since that may crash other tools which parse the output of
'hg log'.
Instead, we teach util.datestr() to return the epoch in timezone UTC+0 on
*all platforms*, represented by the string
Thu Jan 01 00:00:00 1970 +0000
if the timestamp's unix time value is negative.
(based on a patch originally proposed by Benjamin Pollack)
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Tue, 23 Nov 2010 13:11:40 +0100 (2010-11-23) |
parents | 670f4e98276d |
children | 44b26a87f73e 2649be11ab0b |
comparison
equal
deleted
inserted
replaced
13038:670f4e98276d | 13039:dd24f3e7ca9e |
---|---|
1021 """represent a (unixtime, offset) tuple as a localized time. | 1021 """represent a (unixtime, offset) tuple as a localized time. |
1022 unixtime is seconds since the epoch, and offset is the time zone's | 1022 unixtime is seconds since the epoch, and offset is the time zone's |
1023 number of seconds away from UTC. if timezone is false, do not | 1023 number of seconds away from UTC. if timezone is false, do not |
1024 append time zone to string.""" | 1024 append time zone to string.""" |
1025 t, tz = date or makedate() | 1025 t, tz = date or makedate() |
1026 if t < 0: | |
1027 t = 0 # time.gmtime(lt) fails on Windows for lt < -43200 | |
1028 tz = 0 | |
1026 if "%1" in format or "%2" in format: | 1029 if "%1" in format or "%2" in format: |
1027 sign = (tz > 0) and "-" or "+" | 1030 sign = (tz > 0) and "-" or "+" |
1028 minutes = abs(tz) // 60 | 1031 minutes = abs(tz) // 60 |
1029 format = format.replace("%1", "%c%02d" % (sign, minutes // 60)) | 1032 format = format.replace("%1", "%c%02d" % (sign, minutes // 60)) |
1030 format = format.replace("%2", "%02d" % (minutes % 60)) | 1033 format = format.replace("%2", "%02d" % (minutes % 60)) |