diff options
author | Xie Yanbo <xieyanbo@gmail.com> | 2020-07-24 07:10:50 +0800 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2020-07-23 19:13:19 -0400 |
commit | 224c73e34d80caebb34af1e06724fb7858ad732b (patch) | |
tree | 3746e43ed35104029814df4c4396319b1195cf14 /coverage/backward.py | |
parent | db4213b6ac6c85a916f0d58792057ad79456e043 (diff) | |
download | python-coveragepy-git-224c73e34d80caebb34af1e06724fb7858ad732b.tar.gz |
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
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 13 |
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"): |