/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-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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