##// END OF EJS Templates
dates: improve timezone handling...
Matt Mackall -
r6229:c3182eeb default
parent child Browse files
Show More
@@ -210,9 +210,7 b' class notifier(object):'
210 del msg['From']
210 del msg['From']
211 msg['From'] = sender
211 msg['From'] = sender
212
212
213 msg['Date'] = util.datestr(date=util.makedate(),
213 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
214 format="%a, %d %b %Y %H:%M:%S",
215 timezone=True)
216 fix_subject()
214 fix_subject()
217 fix_sender()
215 fix_sender()
218
216
@@ -391,8 +391,7 b' def patchbomb(ui, repo, *revs, **opts):'
391 m['In-Reply-To'] = parent
391 m['In-Reply-To'] = parent
392 else:
392 else:
393 parent = m['Message-Id']
393 parent = m['Message-Id']
394 m['Date'] = util.datestr(date=start_time,
394 m['Date'] = util.datestr(start_time, "%a, %d %b %Y %H:%M:%S %1%2")
395 format="%a, %d %b %Y %H:%M:%S", timezone=True)
396
395
397 start_time = (start_time[0] + 1, start_time[1])
396 start_time = (start_time[0] + 1, start_time[1])
398 m['From'] = sender
397 m['From'] = sender
@@ -419,8 +418,7 b' def patchbomb(ui, repo, *revs, **opts):'
419 elif opts.get('mbox'):
418 elif opts.get('mbox'):
420 ui.status('Writing ', m['Subject'], ' ...\n')
419 ui.status('Writing ', m['Subject'], ' ...\n')
421 fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
420 fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
422 date = util.datestr(date=start_time,
421 date = util.datestr(start_time, '%a %b %d %H:%M:%S %Y')
423 format='%a %b %d %H:%M:%S %Y', timezone=False)
424 fp.write('From %s %s\n' % (sender_addr, date))
422 fp.write('From %s %s\n' % (sender_addr, date))
425 fp.write(m.as_string(0))
423 fp.write(m.as_string(0))
426 fp.write('\n\n')
424 fp.write('\n\n')
@@ -69,14 +69,6 b' def firstline(text):'
69 except IndexError:
69 except IndexError:
70 return ''
70 return ''
71
71
72 def isodate(date):
73 '''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.'''
74 return util.datestr(date, format='%Y-%m-%d %H:%M')
75
76 def hgdate(date):
77 '''turn a (timestamp, tzoff) tuple into an hg cset timestamp.'''
78 return "%d %d" % date
79
80 def nl2br(text):
72 def nl2br(text):
81 '''replace raw newlines with xhtml line breaks.'''
73 '''replace raw newlines with xhtml line breaks.'''
82 return text.replace('\n', '<br/>\n')
74 return text.replace('\n', '<br/>\n')
@@ -142,13 +134,13 b' filters = {'
142 "fill76": lambda x: fill(x, width=76),
134 "fill76": lambda x: fill(x, width=76),
143 "firstline": firstline,
135 "firstline": firstline,
144 "tabindent": lambda x: indent(x, '\t'),
136 "tabindent": lambda x: indent(x, '\t'),
145 "hgdate": hgdate,
137 "hgdate": lambda x: "%d %d" % x,
146 "isodate": isodate,
138 "isodate": lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2'),
147 "obfuscate": obfuscate,
139 "obfuscate": obfuscate,
148 "permissions": permissions,
140 "permissions": permissions,
149 "person": person,
141 "person": person,
150 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"),
142 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2"),
151 "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S", True, "%+03d:%02d"),
143 "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2"),
152 "short": lambda x: x[:12],
144 "short": lambda x: x[:12],
153 "shortdate": util.shortdate,
145 "shortdate": util.shortdate,
154 "stringify": templater.stringify,
146 "stringify": templater.stringify,
@@ -1524,20 +1524,23 b' def makedate():'
1524 tz = time.timezone
1524 tz = time.timezone
1525 return time.mktime(lt), tz
1525 return time.mktime(lt), tz
1526
1526
1527 def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True, timezone_format=" %+03d%02d"):
1527 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
1528 """represent a (unixtime, offset) tuple as a localized time.
1528 """represent a (unixtime, offset) tuple as a localized time.
1529 unixtime is seconds since the epoch, and offset is the time zone's
1529 unixtime is seconds since the epoch, and offset is the time zone's
1530 number of seconds away from UTC. if timezone is false, do not
1530 number of seconds away from UTC. if timezone is false, do not
1531 append time zone to string."""
1531 append time zone to string."""
1532 t, tz = date or makedate()
1532 t, tz = date or makedate()
1533 if "%1" in format or "%2" in format:
1534 sign = (tz > 0) and "-" or "+"
1535 minutes = abs(tz) / 60
1536 format = format.replace("%1", "%c%02d" % (sign, minutes / 60))
1537 format = format.replace("%2", "%02d" % (minutes % 60))
1533 s = time.strftime(format, time.gmtime(float(t) - tz))
1538 s = time.strftime(format, time.gmtime(float(t) - tz))
1534 if timezone:
1535 s += timezone_format % (int(-tz / 3600.0), ((-tz % 3600) / 60))
1536 return s
1539 return s
1537
1540
1538 def shortdate(date=None):
1541 def shortdate(date=None):
1539 """turn (timestamp, tzoff) tuple into iso 8631 date."""
1542 """turn (timestamp, tzoff) tuple into iso 8631 date."""
1540 return datestr(date, format='%Y-%m-%d', timezone=False)
1543 return datestr(date, format='%Y-%m-%d')
1541
1544
1542 def strdate(string, format, defaults=[]):
1545 def strdate(string, format, defaults=[]):
1543 """parse a localized time string and return a (unixtime, offset) tuple.
1546 """parse a localized time string and return a (unixtime, offset) tuple.
@@ -1545,9 +1548,10 b' def strdate(string, format, defaults=[])'
1545 def timezone(string):
1548 def timezone(string):
1546 tz = string.split()[-1]
1549 tz = string.split()[-1]
1547 if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
1550 if tz[0] in "+-" and len(tz) == 5 and tz[1:].isdigit():
1548 tz = int(tz)
1551 sign = (tz[0] == "+") and 1 or -1
1549 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
1552 hours = int(tz[1:3])
1550 return offset
1553 minutes = int(tz[3:5])
1554 return -sign * (hours * 60 + minutes) * 60
1551 if tz == "GMT" or tz == "UTC":
1555 if tz == "GMT" or tz == "UTC":
1552 return 0
1556 return 0
1553 return None
1557 return None
@@ -1601,7 +1605,7 b' def parsedate(date, formats=None, defaul'
1601 elif part[0] in "dm":
1605 elif part[0] in "dm":
1602 defaults[part] = "1"
1606 defaults[part] = "1"
1603 else:
1607 else:
1604 defaults[part] = datestr(now, "%" + part[0], False)
1608 defaults[part] = datestr(now, "%" + part[0])
1605
1609
1606 for format in formats:
1610 for format in formats:
1607 try:
1611 try:
General Comments 0
You need to be logged in to leave comments. Login now