Mercurial > p > roundup > code
comparison roundup/date.py @ 3231:4a5893bfd70d
merge from maint-0-8
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 03 Mar 2005 04:49:16 +0000 |
| parents | ea29d69f7415 |
| children | 9c65e32514aa |
comparison
equal
deleted
inserted
replaced
| 3228:1b15e9eeb592 | 3231:4a5893bfd70d |
|---|---|
| 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.80 2005-02-25 17:15:47 a1s Exp $ | 18 # $Id: date.py,v 1.81 2005-03-03 04:49:16 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 |
| 133 self.set(spec, offset=offset, add_granularity=add_granularity) | 133 self.set(spec, offset=offset, add_granularity=add_granularity) |
| 134 return | 134 return |
| 135 elif have_datetime and isinstance(spec, datetime.datetime): | 135 elif have_datetime and isinstance(spec, datetime.datetime): |
| 136 # Python 2.3+ datetime object | 136 # Python 2.3+ datetime object |
| 137 y,m,d,H,M,S,x,x,x = spec.timetuple() | 137 y,m,d,H,M,S,x,x,x = spec.timetuple() |
| 138 if y < 1970: raise ValueError, 'year must be > 1970' | |
| 138 S += spec.microsecond/1000000. | 139 S += spec.microsecond/1000000. |
| 139 spec = (y,m,d,H,M,S,x,x,x) | 140 spec = (y,m,d,H,M,S,x,x,x) |
| 140 elif hasattr(spec, 'tuple'): | 141 elif hasattr(spec, 'tuple'): |
| 141 spec = spec.tuple() | 142 spec = spec.tuple() |
| 142 elif isinstance(spec, Date): | 143 elif isinstance(spec, Date): |
| 143 spec = spec.get_tuple() | 144 spec = spec.get_tuple() |
| 144 try: | 145 try: |
| 145 y,m,d,H,M,S,x,x,x = spec | 146 y,m,d,H,M,S,x,x,x = spec |
| 147 if y < 1970: raise ValueError, 'year must be > 1970' | |
| 146 frac = S - int(S) | 148 frac = S - int(S) |
| 147 ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0)) | 149 ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0)) |
| 148 self.year, self.month, self.day, self.hour, self.minute, \ | 150 self.year, self.month, self.day, self.hour, self.minute, \ |
| 149 self.second, x, x, x = time.gmtime(ts) | 151 self.second, x, x, x = time.gmtime(ts) |
| 150 # we lost the fractional part | 152 # we lost the fractional part |
| 193 S = S + frac | 195 S = S + frac |
| 194 | 196 |
| 195 if info['y'] is not None or info['a'] is not None: | 197 if info['y'] is not None or info['a'] is not None: |
| 196 if info['y'] is not None: | 198 if info['y'] is not None: |
| 197 y = int(info['y']) | 199 y = int(info['y']) |
| 200 if y < 1970: raise ValueError, 'year must be > 1970' | |
| 198 m,d = (1,1) | 201 m,d = (1,1) |
| 199 if info['m'] is not None: | 202 if info['m'] is not None: |
| 200 m = int(info['m']) | 203 m = int(info['m']) |
| 201 if info['d'] is not None: | 204 if info['d'] is not None: |
| 202 d = int(info['d']) | 205 d = int(info['d']) |
