~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/timestamp.py

  • Committer: Matt Giuca
  • Date: 2011-11-20 01:49:32 UTC
  • mto: This revision was merged to the branch mainline in revision 6282.
  • Revision ID: matt.giuca@gmail.com-20111120014932-s0k0n1sxv3fdj2w6
bzrlib.timestamp: Now checks offset hour and minute to ensure they are within correct range.
Added test cases for invalid offsets +2400, -2400 and -0560.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
        raise ValueError("time data %r does not match format " % date_str
140
140
            + "'%Y-%m-%d %H:%M:%S %z'")
141
141
    secs_str = match.group(1)
142
 
    offset_hours, offset_mins = match.group(2), match.group(3)
143
 
    offset = int(offset_hours) * 3600 + int(offset_mins) * 60
 
142
    offset_hours, offset_mins = int(match.group(2)), int(match.group(3))
 
143
    if abs(offset_hours) >= 24 or offset_mins >= 60:
 
144
        raise ValueError("invalid timezone %r" %
 
145
            (match.group(2) + match.group(3)))
 
146
    offset = offset_hours * 3600 + offset_mins * 60
144
147
    tm_time = time.strptime(secs_str, '%Y-%m-%d %H:%M:%S')
145
148
    # adjust seconds according to offset before converting to POSIX
146
149
    # timestamp, to avoid edge problems