Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 1321:b47f96a178a3
Clean up date and timezone handling.
We used to pass changelog dates around as a "unixtime timezone" string
containing a pair of encoded ints. Now, they get passed around as a
(unixtime, timezone) tuple of numbers, which makes much more sense.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 22 Sep 2005 23:19:47 -0700 |
parents | 5f277e73778f |
children | 8f06817bf266 |
line wrap: on
line diff
--- a/mercurial/util.py Thu Sep 22 22:46:50 2005 -0700 +++ b/mercurial/util.py Thu Sep 22 23:19:47 2005 -0700 @@ -544,21 +544,17 @@ yield s s = f.read(size) -def datestr(change=None, format='%c'): - """represent a change date as a localized time. - a change date is a 'unixtime offset' string, where unixtime is - seconds since the epoch, and offset is seconds away from UTC.""" - if change is None: - t = time.time() - if time.daylight: tz = time.altzone - else: tz = time.timezone - else: - t, tz = change[2].split(' ') - try: - # a conversion tool was sticking non-integer offsets into repos - tz = int(tz) - except ValueError: - tz = 0 +def makedate(): + t = time.time() + if time.daylight: tz = time.altzone + else: tz = time.timezone + return t, tz + +def datestr(date=None, format='%c'): + """represent a (unixtime, offset) tuple as a localized time. + unixtime is seconds since the epoch, and offset is the time zone's + number of seconds away from UTC.""" + t, tz = date or makedate() return ("%s %+03d%02d" % (time.strftime(format, time.gmtime(float(t) - tz)), -tz / 3600,