[Git][NTPsec/ntpsec][master] ntpdig: Use python's built-in UTC offset variables since they handle DST
Matt Selsky
gitlab at mg.gitlab.com
Mon May 22 07:31:54 UTC 2017
Matt Selsky pushed to branch master at NTPsec / ntpsec
Commits:
481fd8be by Matt Selsky at 2017-05-22T11:58:50+04:30
ntpdig: Use python's built-in UTC offset variables since they handle DST
Also avoid printing the negative sign twice
Fixes GitLab issue #311
- - - - -
1 changed file:
- ntpclients/ntpdig
Changes:
=====================================
ntpclients/ntpdig
=====================================
--- a/ntpclients/ntpdig
+++ b/ntpclients/ntpdig
@@ -193,10 +193,10 @@ def report(packet, json):
packet.posixize()
- # Cheesy way to get local timezone offset
- gmt_time = int(time.time())
- local_time = int(time.mktime(time.gmtime(gmt_time)))
- tmoffset = (local_time - gmt_time) // 60 # In minutes
+ if time.daylight:
+ tmoffset = time.altzone // 60 # In minutes
+ else:
+ tmoffset = time.timezone // 60 # In minutes
# The server's idea of the time
t = time.localtime(int(packet.transmit_timestamp))
@@ -208,7 +208,7 @@ def report(packet, json):
date = time.strftime("%Y-%m-%d", t)
tod = time.strftime("%T", t) + (".%*d" % (digits, ms))
sgn = ("%+d" % tmoffset)[0]
- tz = "%s%02d%02d" % (sgn, tmoffset // 60, tmoffset % 60)
+ tz = "%s%02d%02d" % (sgn, abs(tmoffset) // 60, tmoffset % 60)
if json:
say('{"time":"%sT%s%s","offset":%f,"precision":%f,"host":"%s",'
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/481fd8be3147e078f85e31636beec0c1ff49c503
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/481fd8be3147e078f85e31636beec0c1ff49c503
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/20170522/dcf61b90/attachment.html>
More information about the vc
mailing list