comparison roundup/date.py @ 2702:eb4e7b8d52a2

handle Py2.3+ datetime objects as Date specs [SF#971300]
author Richard Jones <richard@users.sourceforge.net>
date Wed, 29 Sep 2004 07:27:09 +0000
parents 92510df07670
children 797725ec50c5
comparison
equal deleted inserted replaced
2701:460c07a2dff1 2702:eb4e7b8d52a2
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.74 2004-07-04 05:07:19 richard Exp $ 18 # $Id: date.py,v 1.75 2004-09-29 07:27:08 richard Exp $
19 19
20 """Date, time and time interval handling. 20 """Date, time and time interval handling.
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
24 import time, re, calendar 24 import time, re, calendar
25 from types import * 25 from types import *
26 import i18n 26 import i18n
27
28 try:
29 import datetime
30 have_datetime = 1
31 except:
32 have_datetime = 0
27 33
28 def _add_granularity(src, order, value = 1): 34 def _add_granularity(src, order, value = 1):
29 '''Increment first non-None value in src dictionary ordered by 'order' 35 '''Increment first non-None value in src dictionary ordered by 'order'
30 parameter 36 parameter
31 ''' 37 '''
124 """ 130 """
125 self.setTranslator(translator) 131 self.setTranslator(translator)
126 if type(spec) == type(''): 132 if type(spec) == type(''):
127 self.set(spec, offset=offset, add_granularity=add_granularity) 133 self.set(spec, offset=offset, add_granularity=add_granularity)
128 return 134 return
135 elif have_datetime and isinstance(spec, datetime.datetime):
136 # Python 2.3+ datetime object
137 y,m,d,H,M,S,x,x,x = spec.timetuple()
138 S += spec.microsecond/1000000.
139 spec = (y,m,d,H,M,S,x,x,x)
129 elif hasattr(spec, 'tuple'): 140 elif hasattr(spec, 'tuple'):
130 spec = spec.tuple() 141 spec = spec.tuple()
131 elif isinstance(spec, Date): 142 elif isinstance(spec, Date):
132 spec = spec.get_tuple() 143 spec = spec.get_tuple()
133 try: 144 try:

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