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

Merge test-run support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        offset = 0
60
60
    tt = time.gmtime(t + offset)
61
61
 
62
 
    return (osutils.weekdays[tt[6]] + time.strftime(" %Y-%m-%d %H:%M:%S", tt) +
 
62
    return (osutils.weekdays[tt[6]] +
 
63
            time.strftime(" %Y-%m-%d %H:%M:%S", tt)
63
64
            # Get the high-res seconds, but ignore the 0
64
 
            ('%.9f' % (t - int(t)))[1:] +
65
 
            ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
 
65
            + ('%.9f' % (t - int(t)))[1:]
 
66
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
66
67
 
67
68
 
68
69
def unpack_highres_date(date):
112
113
    """
113
114
    if offset % 60 != 0:
114
115
        raise ValueError(
115
 
            "can't represent timezone %s offset by fractional minutes" % offset)
 
116
        "can't represent timezone %s offset by fractional minutes" % offset)
116
117
    # so that we don't need to do calculations on pre-epoch times,
117
118
    # which doesn't work with win32 python gmtime, we always
118
119
    # give the epoch in utc
121
122
    if secs + offset < 0:
122
123
        from warnings import warn
123
124
        warn("gmtime of negative time (%s, %s) may not work on Windows" %
124
 
             (secs, offset))
 
125
                (secs, offset))
125
126
    return osutils.format_date(secs, offset=offset,
126
 
                               date_fmt='%Y-%m-%d %H:%M:%S')
 
127
            date_fmt='%Y-%m-%d %H:%M:%S')
127
128
 
128
129
 
129
130
# Format for patch dates: %Y-%m-%d %H:%M:%S [+-]%H%M
130
131
# Groups: 1 = %Y-%m-%d %H:%M:%S; 2 = [+-]%H; 3 = %M
131
 
RE_PATCHDATE = re.compile(
132
 
    "(\\d+-\\d+-\\d+\\s+\\d+:\\d+:\\d+)\\s*([+-]\\d\\d)(\\d\\d)$")
 
132
RE_PATCHDATE = re.compile("(\\d+-\\d+-\\d+\\s+\\d+:\\d+:\\d+)\\s*([+-]\\d\\d)(\\d\\d)$")
133
133
RE_PATCHDATE_NOOFFSET = re.compile("\\d+-\\d+-\\d+\\s+\\d+:\\d+:\\d+$")
134
134
 
135
 
 
136
135
def parse_patch_date(date_str):
137
136
    """Parse a patch-style date into a POSIX timestamp and offset.
138
137
 
142
141
    if match is None:
143
142
        if RE_PATCHDATE_NOOFFSET.match(date_str) is not None:
144
143
            raise ValueError("time data %r is missing a timezone offset"
145
 
                             % date_str)
 
144
                % date_str)
146
145
        else:
147
 
            raise ValueError("time data %r does not match format " % date_str +
148
 
                             "'%Y-%m-%d %H:%M:%S %z'")
 
146
            raise ValueError("time data %r does not match format " % date_str
 
147
                + "'%Y-%m-%d %H:%M:%S %z'")
149
148
    secs_str = match.group(1)
150
149
    offset_hours, offset_mins = int(match.group(2)), int(match.group(3))
151
150
    if abs(offset_hours) >= 24 or offset_mins >= 60:
152
151
        raise ValueError("invalid timezone %r" %
153
 
                         (match.group(2) + match.group(3)))
 
152
            (match.group(2) + match.group(3)))
154
153
    offset = offset_hours * 3600 + offset_mins * 60
155
154
    tm_time = time.strptime(secs_str, '%Y-%m-%d %H:%M:%S')
156
155
    # adjust seconds according to offset before converting to POSIX