comparison roundup/date.py @ 3460:c75dd71a7963 maint-0.8

merge from HEAD
author Richard Jones <richard@users.sourceforge.net>
date Fri, 13 Jan 2006 01:29:48 +0000
parents ff490d669015
children
comparison
equal deleted inserted replaced
3451:f18c0245a170 3460:c75dd71a7963
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: date.py,v 1.77.2.4 2005-03-03 04:47:35 richard Exp $ 18 # $Id: date.py,v 1.77.2.5 2006-01-13 01:29:45 richard Exp $
19 19
20 """Date, time and time interval handling. 20 """Date, time and time interval handling.
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
37 ''' 37 '''
38 for gran in order: 38 for gran in order:
39 if src[gran]: 39 if src[gran]:
40 src[gran] = int(src[gran]) + value 40 src[gran] = int(src[gran]) + value
41 break 41 break
42
43 # no, I don't know why we must anchor the date RE when we only ever use it
44 # in a match()
45 date_re = re.compile(r'''^
46 ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]]
47 |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd
48 (?P<n>\.)? # .
49 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss
50 (?P<o>[\d\smyd\-+]+)? # offset
51 $''', re.VERBOSE)
52 serialised_date_re = re.compile(r'''
53 (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?)
54 ''', re.VERBOSE)
42 55
43 class Date: 56 class Date:
44 ''' 57 '''
45 As strings, date-and-time stamps are specified with the date in 58 As strings, date-and-time stamps are specified with the date in
46 international standard format (yyyy-mm-dd) joined to the time 59 international standard format (yyyy-mm-dd) joined to the time
152 # we lost the fractional part 165 # we lost the fractional part
153 self.second = self.second + frac 166 self.second = self.second + frac
154 except: 167 except:
155 raise ValueError, 'Unknown spec %r' % (spec,) 168 raise ValueError, 'Unknown spec %r' % (spec,)
156 169
157 def set(self, spec, offset=0, date_re=re.compile(r''' 170 def set(self, spec, offset=0, date_re=date_re,
158 ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]] 171 serialised_re=serialised_date_re, add_granularity=0):
159 |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd
160 (?P<n>\.)? # .
161 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss
162 (?P<o>.+)? # offset
163 ''', re.VERBOSE), serialised_re=re.compile(r'''
164 (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?)
165 ''', re.VERBOSE), add_granularity=0):
166 ''' set the date to the value in spec 172 ''' set the date to the value in spec
167 ''' 173 '''
168 174
169 m = serialised_re.match(spec) 175 m = serialised_re.match(spec)
170 if m is not None: 176 if m is not None:

Roundup Issue Tracker: http://roundup-tracker.org/