/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/timestamp.py

  • Committer: Martin Pool
  • Date: 2007-04-19 07:17:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2461.
  • Revision ID: mbp@sourcefrog.net-20070419071716-tcuv5i38vhci6fuf
Fix formatting of timezones in bundles and merge directives.
Always give epoch time in utc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
 
128
128
    Inverse of parse_patch_date.
129
129
    """
130
 
    assert offset % 36 == 0
 
130
    assert offset % 60 == 0, \
 
131
        "can't represent timezone %s offset by fractional minutes" % offset
 
132
    # so that we don't need to do calculations on pre-epoch times, 
 
133
    # which doesn't work with win32 python gmtime, we always
 
134
    # give the epoch in utc
 
135
    if secs == 0:
 
136
        offset = 0
 
137
    if secs + offset < 0:
 
138
        from warnings import warn
 
139
        warn("gmtime of negative time (%s, %s) may not work on Windows" %
 
140
                (secs, offset))
131
141
    tm = time.gmtime(secs+offset)
132
142
    time_str = time.strftime('%Y-%m-%d %H:%M:%S', tm)
133
 
    return '%s %+05d' % (time_str, offset/36)
 
143
    return '%s %+03d%02d' % (time_str, offset/3600, abs(offset/60) % 60)
134
144
 
135
145
 
136
146
def parse_patch_date(date_str):
139
149
    Inverse of format_patch_date.
140
150
    """
141
151
    secs_str = date_str[:-6]
142
 
    offset_str = date_str[-6:]
143
 
    offset = int(offset_str) * 36
 
152
    offset_str = date_str[-5:]
 
153
    assert len(offset_str) == 5, \
 
154
            "invalid timezone %r" % offset_str
 
155
    offset_hours, offset_mins = offset_str[:3], offset_str[3:]
 
156
    offset = int(offset_hours) * 3600 + int(offset_mins) * 60
144
157
    tm_time = time.strptime(secs_str, '%Y-%m-%d %H:%M:%S')
145
158
    # adjust seconds according to offset before converting to POSIX
146
159
    # timestamp, to avoid edge problems