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

Lines changed: 4 additions & 0 deletions

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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>

0 commit comments

Comments
 (0)