Commit 0f9294f7 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Remove utils.FormatTimestampWithTZ

Long story short: time.strftime("%Z", time.localtime()) doesn't work,
even though it's documented to be equivalent to time.strftime("%Z").

$ TZ=America/Sao_Paulo python -c 'import time; print
time.strftime("%Z"), time.strftime("%Z", time.localtime())'


Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 9e691184
......@@ -2835,21 +2835,12 @@ def TailFile(fname, lines=20):
return rows[-lines:]
def FormatTimestampWithTZ(secs):
"""Formats a Unix timestamp with the local timezone.
@type secs: number
@param secs: Seconds since the Epoch (1970-01-01 00:00:00 UTC)
return time.strftime("%F %T %Z", time.localtime(secs))
def _ParseAsn1Generalizedtime(value):
"""Parses an ASN1 GENERALIZEDTIME timestamp as used by pyOpenSSL.
@type value: string
@param value: ASN1 GENERALIZEDTIME timestamp
@return: Seconds since the Epoch (1970-01-01 00:00:00 UTC)
m = _ASN1_TIME_REGEX.match(value)
......@@ -2931,19 +2922,18 @@ def _VerifyCertificateInner(expired, not_before, not_after, now,
if not_before is not None and not_after is not None:
msg += (" (valid from %s to %s)" %
(FormatTime(not_before), FormatTime(not_after)))
elif not_before is not None:
msg += " (valid from %s)" % FormatTimestampWithTZ(not_before)
msg += " (valid from %s)" % FormatTime(not_before)
elif not_after is not None:
msg += " (valid until %s)" % FormatTimestampWithTZ(not_after)
msg += " (valid until %s)" % FormatTime(not_after)
return (CERT_ERROR, msg)
elif not_before is not None and not_before > now:
"Certificate not yet valid (valid from %s)" %
elif not_after is not None:
remaining_days = int((not_after - now) / (24 * 3600))
......@@ -1713,25 +1713,6 @@ class TestFormatTime(unittest.TestCase):
class TestFormatTimestampWithTZ(unittest.TestCase):
def _TestInProcess(tz, timestamp, expected):
os.environ["TZ"] = tz
return utils.FormatTimestampWithTZ(timestamp) == expected
def _Test(self, *args):
# Need to use separate process as we want to change TZ
self.assert_(utils.RunInSeparateProcess(self._TestInProcess, *args))
def test(self):
self._Test("UTC", 0, "1970-01-01 00:00:00 UTC")
self._Test("America/Sao_Paulo", 1292606926, "2010-12-17 15:28:46 BRST")
self._Test("Europe/London", 1292606926, "2010-12-17 17:28:46 GMT")
self._Test("Europe/Zurich", 1292606926, "2010-12-17 18:28:46 CET")
self._Test("Australia/Sydney", 1292606926, "2010-12-18 04:28:46 EST")
class RunInSeparateProcess(unittest.TestCase):
def test(self):
for exp in [True, False]:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment