1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Date parsing routines.
19
Each routine returns timestamp,timezone where
21
* timestamp is seconds since epoch
22
* timezone is the offset from UTC in seconds.
30
"""Parse a date from a raw string.
32
The format must be exactly "seconds-since-epoch offset-utc".
33
See the spec for details.
35
timestamp_str, timezone_str = s.split(' ', 1)
36
timestamp = float(timestamp_str)
37
timezone = _parse_tz(timezone_str)
38
return timestamp, timezone
42
"""Parse a timezone specification in the [+|-]HHMM format.
44
:return: the timezone offset in seconds.
46
# from git_repository.py in bzr-git
48
sign = {'+': +1, '-': -1}[tz[0]]
51
return sign * 60 * (60 * hours + minutes)
55
"""Parse a date from a rfc2822 string.
57
See the spec for details.
59
raise NotImplementedError(parse_rfc2822)
63
"""Parse a date from a string.
65
The format must be exactly "now".
66
See the spec for details.
71
# Lookup tabel of date parsing routines
72
DATE_PARSERS_BY_NAME = {
74
'rfc2822': parse_rfc2822,