/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

Minor improvements to log performance by calling outf.write once (only) per revision and tuning date formatting speed

Show diffs side-by-side

added added

removed removed

Lines of Context:
695
695
    return offset.days * 86400 + offset.seconds
696
696
 
697
697
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
 
698
_default_format_by_weekday_num = [wd + " %Y-%m-%d %H:%M:%S" for wd in weekdays]
 
699
 
698
700
 
699
701
def format_date(t, offset=0, timezone='original', date_fmt=None,
700
702
                show_offset=True):
714
716
    date_str = time.strftime(date_fmt, tt)
715
717
    return date_str + offset_str
716
718
 
 
719
 
 
720
# Cache of formatted offset strings
 
721
_offset_cache = {}
 
722
 
 
723
 
 
724
def format_date_with_offset_in_original_timezone(t, offset=0,
 
725
    _cache=_offset_cache):
 
726
    """Return a formatted date string in the original timezone.
 
727
 
 
728
    This routine may be faster then format_date.
 
729
 
 
730
    :param t: Seconds since the epoch.
 
731
    :param offset: Timezone offset in seconds east of utc.
 
732
    """
 
733
    if offset is None:
 
734
        offset = 0
 
735
    tt = time.gmtime(t + offset)
 
736
    date_fmt = _default_format_by_weekday_num[tt[6]]
 
737
    date_str = time.strftime(date_fmt, tt)
 
738
    offset_str = _cache.get(offset, None)
 
739
    if offset_str is None:
 
740
        offset_str = ' %+03d%02d' % (offset / 3600, (offset / 60) % 60)
 
741
        _cache[offset] = offset_str
 
742
    return date_str + offset_str
 
743
 
 
744
 
717
745
def format_local_date(t, offset=0, timezone='original', date_fmt=None,
718
746
                      show_offset=True):
719
747
    """Return an unicode date string formatted according to the current locale.
733
761
        date_str = date_str.decode(get_user_encoding(), 'replace')
734
762
    return date_str + offset_str
735
763
 
 
764
 
736
765
def _format_date(t, offset, timezone, date_fmt, show_offset):
737
766
    if timezone == 'utc':
738
767
        tt = time.gmtime(t)