--- a/src/pyams_utils/timezone/__init__.py Wed Oct 07 17:46:02 2015 +0200
+++ b/src/pyams_utils/timezone/__init__.py Wed Oct 07 17:46:56 2015 +0200
@@ -49,6 +49,10 @@
def tztime(value):
+ """Convert datetime to local timezone
+
+ Value is assumed to be in GMT if no timezone is given
+ """
if not value:
return None
if not isinstance(value, datetime):
@@ -59,6 +63,10 @@
def gmtime(value):
+ """Convert datetime to GMT
+
+ Value is assumed to be in GMT if no timezone is given
+ """
if not value:
return None
if not isinstance(value, datetime):
@@ -66,3 +74,17 @@
if not value.tzinfo:
value = GMT.localize(value)
return value.astimezone(GMT)
+
+
+def localgmtime(value):
+ """Convert datetime to GMT
+
+ Value is assumed to be in server timezone if none is given
+ """
+ if not value:
+ return None
+ if not isinstance(value, datetime):
+ return value
+ if not value.tzinfo:
+ value = tzinfo().localize(value)
+ return value.astimezone(GMT)