Add check between date and datetime in timezone functions ZTK-1.1
authorThierry Florac <tflorac@ulthar.net>
Tue, 07 May 2013 15:41:57 +0200
branchZTK-1.1
changeset 214 91a1aa280326
parent 213 ec49fc38bcb4
child 215 7defe29db26d
Add check between date and datetime in timezone functions
docs/HISTORY.txt
src/ztfy/utils/timezone/__init__.py
--- a/docs/HISTORY.txt	Tue Apr 23 11:16:12 2013 +0200
+++ b/docs/HISTORY.txt	Tue May 07 15:41:57 2013 +0200
@@ -5,6 +5,7 @@
 -----
  - small correction in getHumanSize() function
  - added dates formatting functions
+ - added check between date and datetime types in timezone module
 
 0.4.1
 -----
--- a/src/ztfy/utils/timezone/__init__.py	Tue Apr 23 11:16:12 2013 +0200
+++ b/src/ztfy/utils/timezone/__init__.py	Tue May 07 15:41:57 2013 +0200
@@ -17,6 +17,7 @@
 
 # import standard packages
 import pytz
+from datetime import date
 
 # import Zope3 interfaces
 from zope.interface.common.idatetime import ITZInfo
@@ -48,6 +49,8 @@
 def tztime(value):
     if not value:
         return None
+    if isinstance(value, date):
+        return value
     if not value.tzinfo:
         value = GMT.localize(value)
     return value.astimezone(tzinfo())
@@ -56,6 +59,8 @@
 def gmtime(value):
     if not value:
         return None
+    if isinstance(value, date):
+        return value
     if not value.tzinfo:
         value = GMT.localize(value)
     return value.astimezone(GMT)