/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 dates.py

  • Committer: Ian Clatworthy
  • Date: 2009-03-04 04:45:04 UTC
  • mto: (0.64.137 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@internode.on.net-20090304044504-spyw5b2tl5aguyp1
improve error msg when bad timezone encountered

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import time
27
27
 
28
 
 
29
 
def parse_raw(s):
 
28
from bzrlib.plugins.fastimport import errors
 
29
 
 
30
 
 
31
def parse_raw(s, lineno=0):
30
32
    """Parse a date from a raw string.
31
33
    
32
34
    The format must be exactly "seconds-since-epoch offset-utc".
34
36
    """
35
37
    timestamp_str, timezone_str = s.split(' ', 1)
36
38
    timestamp = float(timestamp_str)
37
 
    timezone = _parse_tz(timezone_str)
 
39
    timezone = _parse_tz(timezone_str, lineno)
38
40
    return timestamp, timezone
39
41
 
40
42
 
41
 
def _parse_tz(tz):
 
43
def _parse_tz(tz, lineno):
42
44
    """Parse a timezone specification in the [+|-]HHMM format.
43
45
 
44
46
    :return: the timezone offset in seconds.
45
47
    """
46
48
    # from git_repository.py in bzr-git
47
 
    assert len(tz) == 5
 
49
    if len(tz) != 5:
 
50
        raise errors.InvalidTimezone(lineno, tz)
48
51
    sign = {'+': +1, '-': -1}[tz[0]]
49
52
    hours = int(tz[1:3])
50
53
    minutes = int(tz[3:])
51
54
    return sign * 60 * (60 * hours + minutes)
52
55
 
53
56
 
54
 
def parse_rfc2822(s):
 
57
def parse_rfc2822(s, lineno=0):
55
58
    """Parse a date from a rfc2822 string.
56
59
    
57
60
    See the spec for details.
59
62
    raise NotImplementedError(parse_rfc2822)
60
63
 
61
64
 
62
 
def parse_now(s):
 
65
def parse_now(s, lineno=0):
63
66
    """Parse a date from a string.
64
67
 
65
68
    The format must be exactly "now".