/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

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