[Git][NTPsec/ntpsec][master] ntpviz: Fix timezone handling.
Gary E. Miller (@garyedmundsmiller)
gitlab at mg.gitlab.com
Thu Dec 19 02:37:20 UTC 2024
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
399bf9d3 by Fred Wright at 2024-12-17T20:31:02-08:00
ntpviz: Fix timezone handling.
The attempt to fix the deprecation warning for utcfromtimestamp
resulted in two different versions that didn't work in Python 2. This
uses the last version with a fallback to the original version in
Python 2.
TESTED:
Tested a copy of this code fragment in Python 2.6-2.7 and 3.3-3.13.
Did not test the full ntpviz since it takes too long.
- - - - -
1 changed file:
- ntpclients/ntpviz.py
Changes:
=====================================
ntpclients/ntpviz.py
=====================================
@@ -1811,10 +1811,16 @@ tbody tr:nth-child(6n+6) {
# Ugh. Not clear what to do in the multiplot case
if len(statlist) == 1:
- start_time = datetime.datetime.fromtimestamp(
- stats.starttime, datetime.timezone.utc).strftime('%c')
- end_time = datetime.datetime.fromtimestamp(
- stats.endtime, datetime.timezone.utc).strftime('%c')
+ try:
+ start_time = datetime.datetime.fromtimestamp(
+ stats.starttime, datetime.timezone.utc).strftime('%c')
+ end_time = datetime.datetime.fromtimestamp(
+ stats.endtime, datetime.timezone.utc).strftime('%c')
+ except AttributeError: # No datetime.timezone in Python 2
+ start_time = datetime.datetime.utcfromtimestamp(
+ stats.starttime).strftime('%c')
+ end_time = datetime.datetime.utcfromtimestamp(
+ stats.endtime).strftime('%c')
index_header += '<b>Start Time:</b> %s UTC<br>\n' \
'<b>End Time:</b> %s UTC<br>\n' \
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/399bf9d3a3e2db92edeb0b507a76c0ce6f0681fe
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/399bf9d3a3e2db92edeb0b507a76c0ce6f0681fe
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20241219/33527a15/attachment-0001.htm>
More information about the vc
mailing list