/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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:19:12 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7294.
  • Revision ID: jelmer@jelmer.uk-20181116231912-e043vpq22bdkxa6q
Merge trunk.

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