Skip to content

Commit 224c73e

Browse files
xybnedbat
authored andcommitted
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
1 parent db4213b commit 224c73e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+64
-40
lines changed

CHANGES.rst

+4

CONTRIBUTORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Thijs Triemstra
135135
Titus Brown
136136
Vince Salvino
137137
Ville Skyttä
138+
Xie Yanbo
138139
Yury Selivanov
139140
Zac Hatfield-Dodds
140141
Zooko Wilcox-O'Hearn

coverage/backward.py

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import sys
1111

12+
from datetime import datetime
13+
1214
from coverage import env
1315

1416

@@ -217,6 +219,17 @@ def __eq__(self, other):
217219
return self.__dict__ == other.__dict__
218220

219221

222+
def format_local_datetime(dt):
223+
"""Return a string with local timezone representing the date.
224+
If python version is lower than 3.6, the time zone is not included.
225+
"""
226+
try:
227+
return dt.astimezone().strftime('%Y-%m-%d %H:%M %z')
228+
except (TypeError, ValueError):
229+
# Datetime.astimezone in Python 3.5 can not handle naive datetime
230+
return dt.strftime('%Y-%m-%d %H:%M')
231+
232+
220233
def invalidate_import_caches():
221234
"""Invalidate any import caches that may or may not exist."""
222235
if importlib and hasattr(importlib, "invalidate_caches"):

coverage/html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import coverage
1313
from coverage import env
14-
from coverage.backward import iitems, SimpleNamespace
14+
from coverage.backward import iitems, SimpleNamespace, format_local_datetime
1515
from coverage.data import add_data_to_hash
1616
from coverage.files import flat_rootname
1717
from coverage.misc import CoverageException, ensure_dir, file_be_gone, Hasher, isolate_module
@@ -200,7 +200,7 @@ def __init__(self, cov):
200200
'__url__': coverage.__url__,
201201
'__version__': coverage.__version__,
202202
'title': title,
203-
'time_stamp': datetime.datetime.now().strftime('%Y-%m-%d %H:%M'),
203+
'time_stamp': format_local_datetime(datetime.datetime.now()),
204204
'extra_css': self.extra_css,
205205
'has_arcs': self.has_arcs,
206206
'show_contexts': self.config.show_contexts,

tests/gold/html/a/a_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2 class="stats">
6161
<div class="content">
6262
<p>
6363
<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>,
64-
created at 2019-10-14 09:27
64+
created at 2019-10-14 09:27 +0000
6565
</p>
6666
</div>
6767
</div>

tests/gold/html/a/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>Coverage report:
7676
<div class="content">
7777
<p>
7878
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
79-
created at 2019-10-14 09:27
79+
created at 2019-10-14 09:27 +0000
8080
</p>
8181
</div>
8282
</div>

tests/gold/html/b_branch/b_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h2 class="stats">
8484
<div class="content">
8585
<p>
8686
<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>,
87-
created at 2019-10-14 09:27
87+
created at 2019-10-14 09:27 +0000
8888
</p>
8989
</div>
9090
</div>

tests/gold/html/b_branch/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h1>Coverage report:
8484
<div class="content">
8585
<p>
8686
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
87-
created at 2019-10-14 09:27
87+
created at 2019-10-14 09:27 +0000
8888
</p>
8989
</div>
9090
</div>

tests/gold/html/bom/2/bom_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h2 class="stats">
6767
<div class="content">
6868
<p>
6969
<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>,
70-
created at 2019-10-14 09:32
70+
created at 2019-10-14 09:32 +0000
7171
</p>
7272
</div>
7373
</div>

tests/gold/html/bom/2/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>Coverage report:
7676
<div class="content">
7777
<p>
7878
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
79-
created at 2019-10-13 11:41
79+
created at 2019-10-13 11:41 +0000
8080
</p>
8181
</div>
8282
</div>

tests/gold/html/bom/bom_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h2 class="stats">
6767
<div class="content">
6868
<p>
6969
<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>,
70-
created at 2019-10-14 09:27
70+
created at 2019-10-14 09:27 +0000
7171
</p>
7272
</div>
7373
</div>

tests/gold/html/bom/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>Coverage report:
7676
<div class="content">
7777
<p>
7878
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
79-
created at 2019-10-14 09:27
79+
created at 2019-10-14 09:27 +0000
8080
</p>
8181
</div>
8282
</div>

tests/gold/html/isolatin1/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>Coverage report:
7676
<div class="content">
7777
<p>
7878
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
79-
created at 2019-10-14 09:27
79+
created at 2019-10-14 09:27 +0000
8080
</p>
8181
</div>
8282
</div>

tests/gold/html/isolatin1/isolatin1_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2 class="stats">
6161
<div class="content">
6262
<p>
6363
<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>,
64-
created at 2019-10-14 09:27
64+
created at 2019-10-14 09:27 +0000
6565
</p>
6666
</div>
6767
</div>

tests/gold/html/omit_1/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h1>Coverage report:
9797
<div class="content">
9898
<p>
9999
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
100-
created at 2019-10-14 09:27
100+
created at 2019-10-14 09:27 +0000
101101
</p>
102102
</div>
103103
</div>

tests/gold/html/omit_1/m1_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_1/m2_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_1/m3_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_1/main_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="stats">
6666
<div class="content">
6767
<p>
6868
<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>,
69-
created at 2019-10-14 09:27
69+
created at 2019-10-14 09:27 +0000
7070
</p>
7171
</div>
7272
</div>

tests/gold/html/omit_2/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ <h1>Coverage report:
9090
<div class="content">
9191
<p>
9292
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
93-
created at 2019-10-14 09:27
93+
created at 2019-10-14 09:27 +0000
9494
</p>
9595
</div>
9696
</div>

tests/gold/html/omit_2/m2_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_2/m3_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_2/main_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="stats">
6666
<div class="content">
6767
<p>
6868
<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>,
69-
created at 2019-10-14 09:27
69+
created at 2019-10-14 09:27 +0000
7070
</p>
7171
</div>
7272
</div>

tests/gold/html/omit_3/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>Coverage report:
8383
<div class="content">
8484
<p>
8585
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
86-
created at 2019-10-14 09:27
86+
created at 2019-10-14 09:27 +0000
8787
</p>
8888
</div>
8989
</div>

tests/gold/html/omit_3/m3_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_3/main_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="stats">
6666
<div class="content">
6767
<p>
6868
<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>,
69-
created at 2019-10-14 09:27
69+
created at 2019-10-14 09:27 +0000
7070
</p>
7171
</div>
7272
</div>

tests/gold/html/omit_4/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ <h1>Coverage report:
9090
<div class="content">
9191
<p>
9292
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
93-
created at 2019-10-14 09:27
93+
created at 2019-10-14 09:27 +0000
9494
</p>
9595
</div>
9696
</div>

tests/gold/html/omit_4/m1_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_4/m3_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_4/main_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="stats">
6666
<div class="content">
6767
<p>
6868
<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>,
69-
created at 2019-10-14 09:27
69+
created at 2019-10-14 09:27 +0000
7070
</p>
7171
</div>
7272
</div>

tests/gold/html/omit_5/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>Coverage report:
8383
<div class="content">
8484
<p>
8585
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
86-
created at 2019-10-14 09:27
86+
created at 2019-10-14 09:27 +0000
8787
</p>
8888
</div>
8989
</div>

tests/gold/html/omit_5/m1_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h2 class="stats">
5858
<div class="content">
5959
<p>
6060
<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>,
61-
created at 2019-10-14 09:27
61+
created at 2019-10-14 09:27 +0000
6262
</p>
6363
</div>
6464
</div>

tests/gold/html/omit_5/main_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 class="stats">
6666
<div class="content">
6767
<p>
6868
<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>,
69-
created at 2019-10-14 09:27
69+
created at 2019-10-14 09:27 +0000
7070
</p>
7171
</div>
7272
</div>

tests/gold/html/other/blah_blah_other_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ <h2 class="stats">
6060
<div class="content">
6161
<p>
6262
<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>,
63-
created at 2019-10-14 09:27
63+
created at 2019-10-14 09:27 +0000
6464
</p>
6565
</div>
6666
</div>

tests/gold/html/other/here_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h2 class="stats">
6262
<div class="content">
6363
<p>
6464
<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>,
65-
created at 2019-10-14 09:27
65+
created at 2019-10-14 09:27 +0000
6666
</p>
6767
</div>
6868
</div>

tests/gold/html/other/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>Coverage report:
8383
<div class="content">
8484
<p>
8585
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
86-
created at 2019-10-14 09:27
86+
created at 2019-10-14 09:27 +0000
8787
</p>
8888
</div>
8989
</div>

tests/gold/html/partial/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h1>Coverage report:
8484
<div class="content">
8585
<p>
8686
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
87-
created at 2019-10-14 12:01
87+
created at 2019-10-14 12:01 +0000
8888
</p>
8989
</div>
9090
</div>

tests/gold/html/partial/partial_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h2 class="stats">
7474
<div class="content">
7575
<p>
7676
<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>,
77-
created at 2019-10-14 12:01
77+
created at 2019-10-14 12:01 +0000
7878
</p>
7979
</div>
8080
</div>

tests/gold/html/styled/a_py.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h2 class="stats">
6262
<div class="content">
6363
<p>
6464
<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>,
65-
created at 2019-10-14 09:27
65+
created at 2019-10-14 09:27 +0000
6666
</p>
6767
</div>
6868
</div>

tests/gold/html/styled/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h1>Coverage report:
7777
<div class="content">
7878
<p>
7979
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
80-
created at 2019-10-14 09:27
80+
created at 2019-10-14 09:27 +0000
8181
</p>
8282
</div>
8383
</div>

tests/gold/html/unicode/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1>Coverage report:
7676
<div class="content">
7777
<p>
7878
<a class="nav" href="https://coverage.readthedocs.io/en/coverage-5.0a9">coverage.py v5.0a9</a>,
79-
created at 2019-10-14 09:27
79+
created at 2019-10-14 09:27 +0000
8080
</p>
8181
</div>
8282
</div>

0 commit comments

Comments
 (0)