652
652
:param timezone: How to display the time: 'utc', 'original' for the
653
653
timezone specified by offset, or 'local' for the process's current
655
:param show_offset: Whether to append the timezone.
656
:param date_fmt: strftime format.
655
:param date_fmt: strftime format.
656
:param show_offset: Whether to append the timezone.
658
(date_fmt, tt, offset_str) = \
659
_format_date(t, offset, timezone, date_fmt, show_offset)
660
date_fmt = date_fmt.replace('%a', weekdays[tt[6]])
661
date_str = time.strftime(date_fmt, tt)
662
return date_str + offset_str
664
def format_local_date(t, offset=0, timezone='original', date_fmt=None,
666
"""Return an unicode date string formatted according to the current locale.
668
:param t: Seconds since the epoch.
669
:param offset: Timezone offset in seconds east of utc.
670
:param timezone: How to display the time: 'utc', 'original' for the
671
timezone specified by offset, or 'local' for the process's current
673
:param date_fmt: strftime format.
674
:param show_offset: Whether to append the timezone.
676
(date_fmt, tt, offset_str) = \
677
_format_date(t, offset, timezone, date_fmt, show_offset)
678
date_str = time.strftime(date_fmt, tt)
679
if not isinstance(date_str, unicode):
680
date_str = date_str.decode(bzrlib.user_encoding, 'replace')
681
return date_str + offset_str
683
def _format_date(t, offset, timezone, date_fmt, show_offset):
658
684
if timezone == 'utc':
659
685
tt = time.gmtime(t)
673
699
offset_str = ' %+03d%02d' % (offset / 3600, (offset / 60) % 60)
676
# day of week depends on locale, so we do this ourself
677
date_fmt = date_fmt.replace('%a', weekdays[tt[6]])
678
return (time.strftime(date_fmt, tt) + offset_str)
702
return (date_fmt, tt, offset_str)
681
705
def compact_date(when):