663
663
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
665
665
def format_date(t, offset=0, timezone='original', date_fmt=None,
666
show_offset=True, local_weekday=False):
667
667
"""Return a formatted date string.
669
669
:param t: Seconds since the epoch.
671
671
:param timezone: How to display the time: 'utc', 'original' for the
672
672
timezone specified by offset, or 'local' for the process's current
674
:param show_offset: Whether to append the timezone.
675
:param date_fmt: strftime format.
674
:param date_fmt: strftime format.
675
:param show_offset: Whether to append the timezone.
677
(date_fmt, tt, offset_str) = \
678
_format_date(t, offset, timezone, date_fmt, show_offset)
679
date_fmt = date_fmt.replace('%a', weekdays[tt[6]])
680
date_str = time.strftime(date_fmt, tt)
681
return date_str + offset_str
683
def format_local_date(t, offset=0, timezone='original', date_fmt=None,
685
"""Return an unicode date string formatted according to the current locale.
687
:param t: Seconds since the epoch.
688
:param offset: Timezone offset in seconds east of utc.
689
:param timezone: How to display the time: 'utc', 'original' for the
690
timezone specified by offset, or 'local' for the process's current
692
:param date_fmt: strftime format.
693
:param show_offset: Whether to append the timezone.
695
(date_fmt, tt, offset_str) = \
696
_format_date(t, offset, timezone, date_fmt, show_offset)
697
date_str = time.strftime(date_fmt, tt)
698
if not isinstance(date_str, unicode):
699
date_str = date_str.decode(bzrlib.user_encoding, 'replace')
700
return date_str + offset_str
702
def _format_date(t, offset, timezone, date_fmt, show_offset):
677
703
if timezone == 'utc':
678
704
tt = time.gmtime(t)
692
718
offset_str = ' %+03d%02d' % (offset / 3600, (offset / 60) % 60)
696
date_str = time.strftime(date_fmt, tt)
697
if not isinstance(date_str, unicode):
698
date_str = date_str.decode(bzrlib.user_encoding, 'replace')
700
date_fmt = date_fmt.replace('%a', weekdays[tt[6]])
701
date_str = time.strftime(date_fmt, tt)
702
return date_str + offset_str
721
return (date_fmt, tt, offset_str)
705
724
def compact_date(when):