Andriy Kornatskyy avatar Andriy Kornatskyy committed b3b830c

If timezone is not set in datetime instance it is assumed to be in UTC

Comments (0)

Files changed (1)

src/wheezy/core/datetime.py

 
 """ ``datetime`` module.
 """
+from time import gmtime
+from time import localtime
+from time import mktime
 
 from wheezy.core.introspection import import_name
 
         >>> format_http_datetime(now)
         'Mon, 19 Sep 2011 10:45:30 GMT'
 
+        if timezone is not set in datetime instance the ``stamp``
+        is assumed to be in UTC (``datetime.utcnow``).
+
+        >>> now = datetime(2011, 9, 19, 10, 45, 30, 0)
+        >>> format_http_datetime(now)
+        'Mon, 19 Sep 2011 10:45:30 GMT'
+
+        >>> now = datetime.utcnow()
+        >>> assert format_http_datetime(now)
+
         if ``stamp`` is a string just return it
 
         >>> format_http_datetime('x')
     if isinstance(stamp, datetime):
         if stamp.tzinfo:
             stamp = stamp.astimezone(UTC).timetuple()
-        else:  # pragma: nocover
-            # TODO: the output depends on local timezone
-            stamp = gmtime(mktime(stamp.timetuple()))
+        else:
+            stamp = localtime(mktime(stamp.timetuple()))
     elif isinstance(stamp, str):
         return stamp
     else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.