|
1 ############################################################################## |
|
2 # |
|
3 # Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net> |
|
4 # All Rights Reserved. |
|
5 # |
|
6 # This software is subject to the provisions of the Zope Public License, |
|
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
11 # FOR A PARTICULAR PURPOSE. |
|
12 # |
|
13 ############################################################################## |
|
14 """ |
|
15 |
|
16 $Id: $ |
|
17 """ |
|
18 |
|
19 __version__ = "$Revision: $" |
|
20 __release__ = "$Id: $" |
|
21 __docformat__ = "restructuredtext" |
|
22 |
|
23 # import standard packages |
|
24 from datetime import datetime |
|
25 |
|
26 # import Zope3 interfaces |
|
27 |
|
28 # import local interfaces |
|
29 |
|
30 # import Zope3 packages |
|
31 from zope.datetime import parseDatetimetz |
|
32 |
|
33 # import local packages |
|
34 from timezone import gmtime |
|
35 |
|
36 |
|
37 def unidate(value): |
|
38 """Get specified date converted to unicode ISO format |
|
39 |
|
40 Dates are always assumed to be stored in GMT timezone |
|
41 |
|
42 @param value: input date to convert to unicode |
|
43 @type value: date or datetime |
|
44 @return: input date converted to unicode |
|
45 @rtype: unicode |
|
46 """ |
|
47 if value is not None: |
|
48 value = gmtime(value) |
|
49 return unicode(value.isoformat('T'),'ascii') |
|
50 return None |
|
51 |
|
52 |
|
53 def parsedate(value): |
|
54 """Get date specified in unicode ISO format to Python datetime object |
|
55 |
|
56 Dates are always assumed to be stored in GMT timezone |
|
57 |
|
58 @param value: unicode date to be parsed |
|
59 @type value: unicode |
|
60 @return: the specified value, converted to datetime |
|
61 @rtype: datetime |
|
62 """ |
|
63 if value is not None: |
|
64 return gmtime(parseDatetimetz(value)) |
|
65 return None |
|
66 |
|
67 |
|
68 def datetodatetime(value): |
|
69 """Get datetime value converted from a date or datetime object |
|
70 |
|
71 @param value: a date or datetime value to convert |
|
72 @type value: date or datetime |
|
73 @return: input value converted to datetime |
|
74 @rtype: datetime |
|
75 """ |
|
76 if type(value) is datetime: |
|
77 return value |
|
78 return datetime(value.year, value.month, value.day) |