Mercurial > p > roundup > code
comparison roundup/date.py @ 1183:08a13a84ed43
Some speedups - both of the SQL backends can handle using only one cursor.
Better date unserialisation too.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 23 Sep 2002 06:48:35 +0000 |
| parents | db787cef1385 |
| children | 945369929bf8 |
comparison
equal
deleted
inserted
replaced
| 1182:cb35cf3db0e0 | 1183:08a13a84ed43 |
|---|---|
| 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.28 2002-09-10 12:44:42 richard Exp $ | 18 # $Id: date.py,v 1.29 2002-09-23 06:48:34 richard Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Date, time and time interval handling. | 21 Date, time and time interval handling. |
| 22 """ | 22 """ |
| 23 | 23 |
| 218 (((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd | 218 (((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd |
| 219 (?P<n>\.)? # . | 219 (?P<n>\.)? # . |
| 220 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss | 220 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss |
| 221 (?P<o>.+)? # offset | 221 (?P<o>.+)? # offset |
| 222 ''', re.VERBOSE), serialised_re=re.compile(''' | 222 ''', re.VERBOSE), serialised_re=re.compile(''' |
| 223 (?P<y>\d{4})(?P<m>\d{2})(?P<d>\d{2}) # yyyymmdd | 223 (\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}) |
| 224 (?P<H>\d{2})(?P<M>\d{2})(?P<S>\d{2}) # HHMMSS | 224 ''')): |
| 225 ''', re.VERBOSE)): | |
| 226 ''' set the date to the value in spec | 225 ''' set the date to the value in spec |
| 227 ''' | 226 ''' |
| 228 m = serialised_re.match(spec) | 227 m = serialised_re.match(spec) |
| 228 if m: | |
| 229 # we're serialised - easy! | |
| 230 self.year, self.month, self.day, self.hour, self.minute, \ | |
| 231 self.second = map(int, m.groups()[1:7]) | |
| 232 return | |
| 233 | |
| 234 # not serialised data, try usual format | |
| 235 m = date_re.match(spec) | |
| 229 if not m: | 236 if not m: |
| 230 m = date_re.match(spec) | 237 raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].' |
| 231 if not m: | 238 '[[h]h:mm[:ss]][offset]') |
| 232 raise ValueError, _('Not a date spec: [[yyyy-]mm-dd].' | |
| 233 '[[h]h:mm[:ss]][offset]') | |
| 234 | 239 |
| 235 info = m.groupdict() | 240 info = m.groupdict() |
| 236 | 241 |
| 237 # get the current date/time using the offset | 242 # get the current date/time using the offset |
| 238 y,m,d,H,M,S,x,x,x = time.gmtime(time.time()) | 243 y,m,d,H,M,S,x,x,x = time.gmtime(time.time()) |
