Mercurial > p > roundup > code
comparison roundup/date.py @ 1268:b34adc9bcaf2
implemented the missing Interval.__add__
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 11 Oct 2002 01:25:40 +0000 |
| parents | b3279ec4837a |
| children | cae50587fb96 |
comparison
equal
deleted
inserted
replaced
| 1267:a28dfdb6c9a5 | 1268:b34adc9bcaf2 |
|---|---|
| 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.34 2002-10-10 08:24:37 richard Exp $ | 18 # $Id: date.py,v 1.35 2002-10-11 01:25:40 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 |
| 352 l.append('%d:%02d:%02d'%(self.hour, self.minute, self.second)) | 352 l.append('%d:%02d:%02d'%(self.hour, self.minute, self.second)) |
| 353 elif self.hour or self.minute: | 353 elif self.hour or self.minute: |
| 354 l.append('%d:%02d'%(self.hour, self.minute)) | 354 l.append('%d:%02d'%(self.hour, self.minute)) |
| 355 return ' '.join(l) | 355 return ' '.join(l) |
| 356 | 356 |
| 357 def __add__(self, other): | |
| 358 if isinstance(other, Date): | |
| 359 # the other is a Date - produce a Date | |
| 360 return Date(other.addInterval(self)) | |
| 361 elif isinstance(other, Interval): | |
| 362 # add the other Interval to this one | |
| 363 a = self.get_tuple() | |
| 364 b = other.get_tuple() | |
| 365 if b[0] < 0: | |
| 366 i = Interval([x-y for x,y in zip(a[1:],b[1:])]) | |
| 367 else: | |
| 368 i = Interval([x+y for x,y in zip(a[1:],b[1:])]) | |
| 369 return i | |
| 370 # nope, no idea what to do with this other... | |
| 371 raise TypeError, "Can't add %r"%other | |
| 372 | |
| 357 def set(self, spec, interval_re=re.compile(''' | 373 def set(self, spec, interval_re=re.compile(''' |
| 358 \s*(?P<s>[-+])? # + or - | 374 \s*(?P<s>[-+])? # + or - |
| 359 \s*((?P<y>\d+\s*)y)? # year | 375 \s*((?P<y>\d+\s*)y)? # year |
| 360 \s*((?P<m>\d+\s*)m)? # month | 376 \s*((?P<m>\d+\s*)m)? # month |
| 361 \s*((?P<w>\d+\s*)w)? # week | 377 \s*((?P<w>\d+\s*)w)? # week |
