Skip to content

Instantly share code, notes, and snippets.

@ilatypov
Last active June 7, 2017 20:49
Show Gist options
  • Save ilatypov/21655ef94555b9eb2e3d95550dd9f5e2 to your computer and use it in GitHub Desktop.
Save ilatypov/21655ef94555b9eb2e3d95550dd9f5e2 to your computer and use it in GitHub Desktop.
#! /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