comparison mercurial/util.py @ 28865:16255662446d

util: add doctest to datestr()
author Adrian Buehlmann <adrian@cadifra.com>
date Mon, 11 Apr 2016 19:46:50 +0200
parents b0811a9fe67c
children 800ec7c048b0
comparison
equal deleted inserted replaced
28864:b0811a9fe67c 28865:16255662446d
1581 return timestamp, tz 1581 return timestamp, tz
1582 1582
1583 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'): 1583 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
1584 """represent a (unixtime, offset) tuple as a localized time. 1584 """represent a (unixtime, offset) tuple as a localized time.
1585 unixtime is seconds since the epoch, and offset is the time zone's 1585 unixtime is seconds since the epoch, and offset is the time zone's
1586 number of seconds away from UTC.""" 1586 number of seconds away from UTC.
1587
1588 >>> datestr((0, 0))
1589 'Thu Jan 01 00:00:00 1970 +0000'
1590 >>> datestr((42, 0))
1591 'Thu Jan 01 00:00:42 1970 +0000'
1592 >>> datestr((-42, 0))
1593 'Wed Dec 31 23:59:18 1969 +0000'
1594 >>> datestr((0x7fffffff, 0))
1595 'Tue Jan 19 03:14:07 2038 +0000'
1596 >>> datestr((-0x80000000, 0))
1597 'Fri Dec 13 20:45:52 1901 +0000'
1598 """
1587 t, tz = date or makedate() 1599 t, tz = date or makedate()
1588 if "%1" in format or "%2" in format or "%z" in format: 1600 if "%1" in format or "%2" in format or "%z" in format:
1589 sign = (tz > 0) and "-" or "+" 1601 sign = (tz > 0) and "-" or "+"
1590 minutes = abs(tz) // 60 1602 minutes = abs(tz) // 60
1591 q, r = divmod(minutes, 60) 1603 q, r = divmod(minutes, 60)