Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 1320:5f277e73778f
Fix up representation of dates in hgweb.
Date display is now uniform both on the command line and via the web
interface.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 22 Sep 2005 22:46:50 -0700 |
parents | c9cf171f30dd |
children | b47f96a178a3 |
line wrap: on
line diff
--- a/mercurial/util.py Thu Sep 22 21:42:33 2005 -0700 +++ b/mercurial/util.py Thu Sep 22 22:46:50 2005 -0700 @@ -12,7 +12,7 @@ import os, errno from demandload import * -demandload(globals(), "re cStringIO shutil popen2 tempfile threading") +demandload(globals(), "re cStringIO shutil popen2 tempfile threading time") def pipefilter(s, cmd): '''filter string S through command CMD, returning its output''' @@ -543,3 +543,23 @@ while len(s) >= 0: 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 + return ("%s %+03d%02d" % + (time.strftime(format, time.gmtime(float(t) - tz)), + -tz / 3600, + ((-tz % 3600) / 60)))