comparison roundup/date.py @ 4072:d5e2767d4e91

Robustify Date.set.
author Stefan Seefeld <stefan@seefeld.name>
date Mon, 23 Feb 2009 19:24:57 +0000
parents 3d5a0a949107
children ad7176d22f43
comparison
equal deleted inserted replaced
4071:0013d9f65e35 4072:d5e2767d4e91
293 '"yyyy-mm-dd", "mm-dd", "HH:MM", "HH:MM:SS" or ' 293 '"yyyy-mm-dd", "mm-dd", "HH:MM", "HH:MM:SS" or '
294 '"yyyy-mm-dd.HH:MM:SS.SSS"') 294 '"yyyy-mm-dd.HH:MM:SS.SSS"')
295 295
296 info = m.groupdict() 296 info = m.groupdict()
297 297
298 # determine whether we need to add anything at the end 298 # If add_granularity is true, construct the maximum time given
299 # the precision of the input. For example, given the input
300 # "12:15", construct "12:15:59". Or, for "2008", construct
301 # "2008-12-31.23:59:59".
299 if add_granularity: 302 if add_granularity:
300 for gran in 'SMHdmy': 303 for gran in 'SMHdmy':
301 if info[gran] is not None: 304 if info[gran] is not None:
302 if gran == 'S': 305 if gran == 'S':
303 raise ValueError 306 raise ValueError
306 elif gran == 'H': 309 elif gran == 'H':
307 add_granularity = Interval('01:00') 310 add_granularity = Interval('01:00')
308 else: 311 else:
309 add_granularity = Interval('+1%s'%gran) 312 add_granularity = Interval('+1%s'%gran)
310 break 313 break
314 else:
315 raise ValueError(self._('Could not determine granularity'))
311 316
312 # get the current date as our default 317 # get the current date as our default
313 dt = datetime.datetime.utcnow() 318 dt = datetime.datetime.utcnow()
314 y,m,d,H,M,S,x,x,x = dt.timetuple() 319 y,m,d,H,M,S,x,x,x = dt.timetuple()
315 S += dt.microsecond/1000000. 320 S += dt.microsecond/1000000.

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