From 224c73e34d80caebb34af1e06724fb7858ad732b Mon Sep 17 00:00:00 2001 From: Xie Yanbo Date: Fri, 24 Jul 2020 07:10:50 +0800 Subject: Displaying timezone information in HTML report (#960) * Displaying timezone information in HTML report * A helpber to format datetime with local timezone * No backward compatibility with older python versions --- coverage/backward.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'coverage/backward.py') 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"): -- cgit v1.2.1