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 routines a (timestamp,timezone) tuple where
20
timestamp is seconds since epoch and timezone is the offset
29
"""Parse a date from a raw string.
31
The format must be exactly "seconds-since-epoch offset-utc".
32
See the spec for details.
34
timestamp_str, timezone_str = s.split(' ', 1)
35
timestamp = float(timestamp_str)
36
timezone = _parse_tz(timezone_str)
37
return (timestamp, timezone)
41
"""Parse a timezone specification in the [+|-]HHMM format.
43
:return: the timezone offset in seconds.
45
# from git_repository.py in bzr-git
47
sign = {'+': +1, '-': -1}[tz[0]]
50
return sign * 60 * (60 * hours + minutes)
54
"""Parse a date from a rfc2822 string.
56
See the spec for details.
58
raise NotImplementedError(parse_rfc2822)
62
"""Parse a date from a string.
64
The format must be exactly "now".
65
See the spec for details.
67
return (datetime.datetime.now(),0)
70
# Lookup tabel of date parsing routines
71
DATE_PARSERS_BY_NAME = {
73
'rfc2822': parse_rfc2822,