Skip to content

Commit

Permalink
Displaying timezone information in HTML report (#960)
Browse files Browse the repository at this point in the history
* Displaying timezone information in HTML report

* A helpber to format datetime with local timezone

* No backward compatibility with older python versions
  • Loading branch information
xyb authored and nedbat committed Jul 23, 2020
1 parent db4213b commit 224c73e
Show file tree
Hide file tree
Showing 43 changed files with 64 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Unreleased
- The dark mode HTML report still used light colors for the context listing,
making them unreadable (`issue 1009`_). This is now fixed.

- The time stamp on the HTML report now includes the time zone. Thanks, Xie
Yanbo (`pull request 960`_).

.. _pull request 960: https://github.com/nedbat/coveragepy/pull/960
.. _issue 1009: https://github.com/nedbat/coveragepy/issues/1009


Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Thijs Triemstra
Titus Brown
Vince Salvino
Ville Skyttä
Xie Yanbo
Yury Selivanov
Zac Hatfield-Dodds
Zooko Wilcox-O'Hearn
13 changes: 13 additions & 0 deletions coverage/backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import sys

from datetime import datetime

from coverage import env


Expand Down Expand Up @@ -217,6 +219,17 @@ def __eq__(self, other):
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"):
Expand Down
4 changes: 2 additions & 2 deletions coverage/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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
Expand Down Expand Up @@ -200,7 +200,7 @@ def __init__(self, cov):
'__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,
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/a/a_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/a/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/b_branch/b_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/b_branch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/bom/2/bom_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:32
created at 2019-10-14 09:32 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/bom/2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-13 11:41
created at 2019-10-13 11:41 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/bom/bom_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/bom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/isolatin1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/isolatin1/isolatin1_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_1/m1_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_1/m2_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_1/m3_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_1/main_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_2/m2_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_2/m3_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_2/main_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_3/m3_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_3/main_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_4/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_4/m1_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_4/m3_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_4/main_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_5/m1_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/omit_5/main_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/other/blah_blah_other_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/other/here_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/other/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/partial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 12:01
created at 2019-10-14 12:01 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/partial/partial_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 12:01
created at 2019-10-14 12:01 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/styled/a_py.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2 class="stats">
<div class="content">
<p>
<a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/styled/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/gold/html/unicode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>Coverage report:
<div class="content">
<p>
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
created at 2019-10-14 09:27
created at 2019-10-14 09:27 +0000
</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 224c73e

Please sign in to comment.