Last active
June 7, 2017 20:49
-
-
Save ilatypov/21655ef94555b9eb2e3d95550dd9f5e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# This file can be executed by either the Cygwin (os.name == "posix") build or the Windows native (os.name == "nt") build of Python. | |
import sys | |
import os | |
if os.name == "nt": | |
if "TZ" in os.environ: | |
# Windows Python appears confused with the TZ variable | |
# as it sets time.timezone to 0, time.altzone to -3600 (-1 hr) | |
# in the presence of TZ="America/New_York". | |
del os.environ["TZ"] | |
# The module time needs importing before the above workaround with TZ. | |
import time | |
s_since_epoch = int(sys.argv[1]) | |
is_dst = time.daylight and time.localtime(s_since_epoch).tm_isdst | |
zone = time.altzone if is_dst else time.timezone | |
sys.stderr.write("altzone %d, timezone %d\n" % (time.altzone, time.timezone,)) | |
strtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(s_since_epoch)) | |
utcoff = -zone | |
if utcoff > 0: | |
utcsign = "+" | |
else: | |
utcsign = "-" | |
utcoff = -utcoff | |
strtime += ("%s%02d%02d" % (utcsign, utcoff / 3600, (utcoff % 3600) / 60)) | |
print strtime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment