diff --git a/hgext/notify.py b/hgext/notify.py --- a/hgext/notify.py +++ b/hgext/notify.py @@ -210,9 +210,7 @@ class notifier(object): del msg['From'] msg['From'] = sender - msg['Date'] = util.datestr(date=util.makedate(), - format="%a, %d %b %Y %H:%M:%S", - timezone=True) + msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") fix_subject() fix_sender() diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -391,8 +391,7 @@ def patchbomb(ui, repo, *revs, **opts): m['In-Reply-To'] = parent else: parent = m['Message-Id'] - m['Date'] = util.datestr(date=start_time, - format="%a, %d %b %Y %H:%M:%S", timezone=True) + m['Date'] = util.datestr(start_time, "%a, %d %b %Y %H:%M:%S %1%2") start_time = (start_time[0] + 1, start_time[1]) m['From'] = sender @@ -419,8 +418,7 @@ def patchbomb(ui, repo, *revs, **opts): elif opts.get('mbox'): ui.status('Writing ', m['Subject'], ' ...\n') fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+') - date = util.datestr(date=start_time, - format='%a %b %d %H:%M:%S %Y', timezone=False) + date = util.datestr(start_time, '%a %b %d %H:%M:%S %Y') fp.write('From %s %s\n' % (sender_addr, date)) fp.write(m.as_string(0)) fp.write('\n\n') diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -69,14 +69,6 @@ def firstline(text): except IndexError: return '' -def isodate(date): - '''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.''' - return util.datestr(date, format='%Y-%m-%d %H:%M') - -def hgdate(date): - '''turn a (timestamp, tzoff) tuple into an hg cset timestamp.''' - return "%d %d" % date - def nl2br(text): '''replace raw newlines with xhtml line breaks.''' return text.replace('\n', '
\n') @@ -142,13 +134,13 @@ filters = { "fill76": lambda x: fill(x, width=76), "firstline": firstline, "tabindent": lambda x: indent(x, '\t'), - "hgdate": hgdate, - "isodate": isodate, + "hgdate": lambda x: "%d %d" % x, + "isodate": lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2'), "obfuscate": obfuscate, "permissions": permissions, "person": person, - "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), - "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S", True, "%+03d:%02d"), + "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2"), + "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"), "short": lambda x: x[:12], "shortdate": util.shortdate, "stringify": templater.stringify, diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1524,20 +1524,23 @@ def makedate(): tz = time.timezone return time.mktime(lt), tz -def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True, timezone_format=" %+03d%02d"): +def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'): """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. if timezone is false, do not append time zone to string.""" t, tz = date or makedate() + if "%1" in format or "%2" in format: + sign = (tz > 0) and "-" or "+" + minutes = abs(tz) / 60 + format = format.replace("%1", "%c%02d" % (sign, minutes / 60)) + format = format.replace("%2", "%02d" % (minutes % 60)) s = time.strftime(format, time.gmtime(float(t) - tz)) - if timezone: - s += timezone_format % (int(-tz / 3600.0), ((-tz % 3600) / 60)) return s def shortdate(date=None): """turn (timestamp, tzoff) tuple into iso 8631 date.""" - return datestr(date, format='%Y-%m-%d', timezone=False) + return datestr(date, format='%Y-%m-%d') def strdate(string, format, defaults=[]): """parse a localized time string and return a (unixtime, offset) tuple. @@ -1545,9 +1548,10 @@ def strdate(string, format, defaults=[]) def timezone(string): tz = string.split()[-1] if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit(): - tz = int(tz) - offset = - 3600 * (tz / 100) - 60 * (tz % 100) - return offset + sign = (tz[0] == "+") and 1 or -1 + hours = int(tz[1:3]) + minutes = int(tz[3:5]) + return -sign * (hours * 60 + minutes) * 60 if tz == "GMT" or tz == "UTC": return 0 return None @@ -1601,7 +1605,7 @@ def parsedate(date, formats=None, defaul elif part[0] in "dm": defaults[part] = "1" else: - defaults[part] = datestr(now, "%" + part[0], False) + defaults[part] = datestr(now, "%" + part[0]) for format in formats: try: