[PATCH STABLE] do not crash on or store negative timestamps (issue2513)
Benjamin Pollack
benjamin at bitquabit.com
Mon Nov 22 19:34:03 CST 2010
On Nov 22, 2010, at 5:48 PM, Adrian Buehlmann wrote:
>> diff --git a/mercurial/util.py b/mercurial/util.py
>> --- a/mercurial/util.py
>> +++ b/mercurial/util.py
>> @@ -1031,6 +1031,8 @@ def datestr(date=None, format='%a %b %d
>> minutes = abs(tz) // 60
>> format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
>> format = format.replace("%2", "%02d" % (minutes % 60))
>> + if t < 0:
>> + t = 0
>> s = time.strftime(format, time.gmtime(float(t) - tz))
>> return s
>
> Doesn't t=0 still lead to negative arguments for time.gmtime() for
> timezones to the west of Greenwich (e.g. U.S.)?
Correct; I realized that in the channel after I'd already set the patch. Near as I can tell, what matters is not that t < 0, but rather that t < 43200, which is the greatest negative offset that I know of in a timezone. (50400 would be the greatest positive, but because it's ahead of GMT, I don't think we care.)
I'll do a second patch with this and with Nicolas' request for an argument to ValueError.
--Benjamin
More information about the Mercurial-devel
mailing list