1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: date.py,v 1.82 2005-06-08 03:47:09 anthonybaxter Exp $
18+ # $Id: date.py,v 1.83 2006-01-13 00:22:16 richard Exp $
1919
2020"""Date, time and time interval handling.
2121"""
@@ -39,6 +39,19 @@ def _add_granularity(src, order, value = 1):
3939 src [gran ] = int (src [gran ]) + value
4040 break
4141
42+ # no, I don't know why we must anchor the date RE when we only ever use it
43+ # in a match()
44+ date_re = re .compile (r'''^
45+ ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]]
46+ |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd
47+ (?P<n>\.)? # .
48+ (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss
49+ (?P<o>[\d\smyd\-+]+)? # offset
50+ $''' , re .VERBOSE )
51+ serialised_date_re = re .compile (r'''
52+ (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?)
53+ ''' , re .VERBOSE )
54+
4255class Date :
4356 '''
4457 As strings, date-and-time stamps are specified with the date in
@@ -153,15 +166,8 @@ def __init__(self, spec='.', offset=0, add_granularity=0, translator=i18n):
153166 except :
154167 raise ValueError , 'Unknown spec %r' % (spec ,)
155168
156- def set (self , spec , offset = 0 , date_re = re .compile (r'''
157- ((?P<y>\d\d\d\d)([/-](?P<m>\d\d?)([/-](?P<d>\d\d?))?)? # yyyy[-mm[-dd]]
158- |(?P<a>\d\d?)[/-](?P<b>\d\d?))? # or mm-dd
159- (?P<n>\.)? # .
160- (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d(\.\d+)?))?)? # hh:mm:ss
161- (?P<o>.+)? # offset
162- ''' , re .VERBOSE ), serialised_re = re .compile (r'''
163- (\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d?(\.\d+)?)
164- ''' , re .VERBOSE ), add_granularity = 0 ):
169+ def set (self , spec , offset = 0 , date_re = date_re ,
170+ serialised_re = serialised_date_re , add_granularity = 0 ):
165171 ''' set the date to the value in spec
166172 '''
167173
0 commit comments