summaryrefslogtreecommitdiff
path: root/coverage/backward.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/backward.py')
-rw-r--r--coverage/backward.py13
1 files changed, 13 insertions, 0 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"):