|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: date.py,v 1.68.2.2 2004-07-04 09:08:55 richard Exp $ |
| 18 | +# $Id: date.py,v 1.68.2.3 2004-09-29 07:31:32 richard Exp $ |
19 | 19 |
|
20 | 20 | """Date, time and time interval handling. |
21 | 21 | """ |
|
25 | 25 | from types import * |
26 | 26 | from i18n import _ |
27 | 27 |
|
| 28 | +try: |
| 29 | + import datetime |
| 30 | + have_datetime = 1 |
| 31 | +except: |
| 32 | + have_datetime = 0 |
| 33 | + |
28 | 34 | def _add_granularity(src, order, value = 1): |
29 | 35 | '''Increment first non-None value in src dictionary ordered by 'order' |
30 | 36 | parameter |
@@ -121,6 +127,11 @@ def __init__(self, spec='.', offset=0, add_granularity=0): |
121 | 127 | if type(spec) == type(''): |
122 | 128 | self.set(spec, offset=offset, add_granularity=add_granularity) |
123 | 129 | return |
| 130 | + elif have_datetime and isinstance(spec, datetime.datetime): |
| 131 | + # Python 2.3+ datetime object |
| 132 | + y,m,d,H,M,S,x,x,x = spec.timetuple() |
| 133 | + S += spec.microsecond/1000000. |
| 134 | + spec = (y,m,d,H,M,S,x,x,x) |
124 | 135 | elif hasattr(spec, 'tuple'): |
125 | 136 | spec = spec.tuple() |
126 | 137 | elif isinstance(spec, Date): |
|
0 commit comments