summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/backward.py13
-rw-r--r--coverage/html.py4
2 files changed, 15 insertions, 2 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 37b49167..9d1d78e5 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -9,6 +9,8 @@
import os
import sys
+from datetime import datetime
+
from coverage import env
@@ -217,6 +219,17 @@ except ImportError:
return self.__dict__ == other.__dict__
+def format_local_datetime(dt):
+ """Return a string with local timezone representing the date.
+ If python version is lower than 3.6, the time zone is not included.
+ """
+ try:
+ return dt.astimezone().strftime('%Y-%m-%d %H:%M %z')
+ except (TypeError, ValueError):
+ # Datetime.astimezone in Python 3.5 can not handle naive datetime
+ return dt.strftime('%Y-%m-%d %H:%M')
+
+
def invalidate_import_caches():
"""Invalidate any import caches that may or may not exist."""
if importlib and hasattr(importlib, "invalidate_caches"):
diff --git a/coverage/html.py b/coverage/html.py
index 596e1143..3596bbe1 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -11,7 +11,7 @@ import shutil
import coverage
from coverage import env
-from coverage.backward import iitems, SimpleNamespace
+from coverage.backward import iitems, SimpleNamespace, format_local_datetime
from coverage.data import add_data_to_hash
from coverage.files import flat_rootname
from coverage.misc import CoverageException, ensure_dir, file_be_gone, Hasher, isolate_module
@@ -200,7 +200,7 @@ class HtmlReporter(object):
'__url__': coverage.__url__,
'__version__': coverage.__version__,
'title': title,
- 'time_stamp': datetime.datetime.now().strftime('%Y-%m-%d %H:%M'),
+ 'time_stamp': format_local_datetime(datetime.datetime.now()),
'extra_css': self.extra_css,
'has_arcs': self.has_arcs,
'show_contexts': self.config.show_contexts,