This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: time_test fails after strptime()
Type: behavior Stage: resolved
Components: Extension Modules, Tests Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, iritkatriel, pitrou, serhiy.storchaka
Priority: normal Keywords:

Created on 2014-07-25 15:05 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg223955 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-25 15:05
time_test fails when running after any test which uses strptime().

The bug can be easily reproduced by running test_time twice:

$ TZ=Europe/Kiev ./python -m test.regrtest -ugui -v test_time test_time
...
======================================================================
FAIL: test_strptime (test.test_time.TimeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython-2.7/Lib/test/test_time.py", line 120, in test_strptime
    (format, strf_output))
AssertionError: conversion specifier '%Z' failed with 'MSK' input.

----------------------------------------------------------------------

All works on 3.x and with TZ=UTC.

May be this is related to issue13309.
msg255842 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-03 21:40
If call time.localtime() with time before 1990-03-25T03:00, EET is turned to MSK.  I guess this is a time when the Europe/Kiev timezone was introduced.

>>> import os, time
>>> os.environ['TZ'] = 'Europe/Kiev'
>>> time.tzset()
>>> time.localtime(638319599)
time.struct_time(tm_year=1990, tm_mon=3, tm_mday=25, tm_hour=1, tm_min=59, tm_sec=59, tm_wday=6, tm_yday=84, tm_isdst=0)
>>> time.strftime('%Z', time.gmtime())
'MSK'
>>> time.localtime(638319600)
time.struct_time(tm_year=1990, tm_mon=3, tm_mday=25, tm_hour=3, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=84, tm_isdst=1)
>>> time.strftime('%Z', time.gmtime())
'EET'

C function localtime() implicitly calls tzset() and sets global C variables tzname, timezone, and daylight, but these changes are not exposed as variables in the time module. C and Python ideas about timezone becomes different. This looks as a bug in time.localtime() and other functions that implicitly change timezone variables.
msg406806 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-22 22:20
I am unable to reproduce this on 3.11.
msg406825 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-11-23 08:28
Yes, it was 2.7-only issue.

Thank you Irit for checking and closing outdated issues.
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66265
2021-11-23 08:28:45serhiy.storchakasetstatus: pending -> closed
resolution: works for me -> out of date
messages: + msg406825

stage: resolved
2021-11-22 22:20:36iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg406806

resolution: works for me
2015-12-03 21:40:04serhiy.storchakasetmessages: + msg255842
2014-11-17 12:41:35serhiy.storchakasetnosy: + belopolsky, pitrou
2014-07-25 15:05:06serhiy.storchakacreate