comparison roundup/date.py @ 543:22e0edf7da6e

lots of date/interval related changes: more relaxed date format for input
author Richard Jones <richard@users.sourceforge.net>
date Wed, 16 Jan 2002 07:02:57 +0000
parents e0944187229f
children c08fb4921eda
comparison
equal deleted inserted replaced
542:d17eecdcfe35 543:22e0edf7da6e
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.16 2002-01-08 11:56:24 richard Exp $ 18 # $Id: date.py,v 1.17 2002-01-16 07:02:57 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
151 self.second - other.sign * other.second, 0, 0, 0) 151 self.second - other.sign * other.second, 0, 0, 0)
152 return Date(time.gmtime(calendar.timegm(t))) 152 return Date(time.gmtime(calendar.timegm(t)))
153 153
154 def __cmp__(self, other): 154 def __cmp__(self, other):
155 """Compare this date to another date.""" 155 """Compare this date to another date."""
156 if other is None:
157 return 1
156 for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'): 158 for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
157 r = cmp(getattr(self, attr), getattr(other, attr)) 159 r = cmp(getattr(self, attr), getattr(other, attr))
158 if r: return r 160 if r: return r
159 return 0 161 return 0
160 162
168 ''' 170 '''
169 return time.strftime('%e %B %Y', (self.year, self.month, 171 return time.strftime('%e %B %Y', (self.year, self.month,
170 self.day, self.hour, self.minute, self.second, 0, 0, 0)) 172 self.day, self.hour, self.minute, self.second, 0, 0, 0))
171 173
172 def set(self, spec, offset=0, date_re=re.compile(r''' 174 def set(self, spec, offset=0, date_re=re.compile(r'''
173 (((?P<y>\d\d\d\d)-)?((?P<m>\d\d)-(?P<d>\d\d))?)? # yyyy-mm-dd 175 (((?P<y>\d\d\d\d)-)?((?P<m>\d\d?)-(?P<d>\d\d?))?)? # yyyy-mm-dd
174 (?P<n>\.)? # . 176 (?P<n>\.)? # .
175 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss 177 (((?P<H>\d?\d):(?P<M>\d\d))?(:(?P<S>\d\d))?)? # hh:mm:ss
176 (?P<o>.+)? # offset 178 (?P<o>.+)? # offset
177 ''', re.VERBOSE)): 179 ''', re.VERBOSE)):
178 ''' set the date to the value in spec 180 ''' set the date to the value in spec
252 self.year, self.month, self.day, self.hour, self.minute, \ 254 self.year, self.month, self.day, self.hour, self.minute, \
253 self.second = spec 255 self.second = spec
254 256
255 def __cmp__(self, other): 257 def __cmp__(self, other):
256 """Compare this interval to another interval.""" 258 """Compare this interval to another interval."""
259 if other is None:
260 return 1
257 for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'): 261 for attr in ('year', 'month', 'day', 'hour', 'minute', 'second'):
258 r = cmp(getattr(self, attr), getattr(other, attr)) 262 r = cmp(getattr(self, attr), getattr(other, attr))
259 if r: return r 263 if r: return r
260 return 0 264 return 0
261 265
377 if __name__ == '__main__': 381 if __name__ == '__main__':
378 test() 382 test()
379 383
380 # 384 #
381 # $Log: not supported by cvs2svn $ 385 # $Log: not supported by cvs2svn $
386 # Revision 1.16 2002/01/08 11:56:24 richard
387 # missed an import _
388 #
382 # Revision 1.15 2002/01/05 02:27:00 richard 389 # Revision 1.15 2002/01/05 02:27:00 richard
383 # I18N'ification 390 # I18N'ification
384 # 391 #
385 # Revision 1.14 2001/11/22 15:46:42 jhermann 392 # Revision 1.14 2001/11/22 15:46:42 jhermann
386 # Added module docstrings to all modules. 393 # Added module docstrings to all modules.

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