summaryrefslogtreecommitdiff
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 11:05:55 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 11:06:03 +0900
commit752ffe24f181daff5b50cc59a05e4a7606ce1a62 (patch)
treed5327ce5cd232cb307d637e846e3f27a86a98433 /Lib/_strptime.py
parent6cc694c4c77aac634cca05c9943b43f22bbe042a (diff)
downloadpython-752ffe24f181daff5b50cc59a05e4a7606ce1a62.tar.gz
python-752ffe24f181daff5b50cc59a05e4a7606ce1a62.tar.bz2
python-752ffe24f181daff5b50cc59a05e4a7606ce1a62.zip
Imported Upstream version 2.7.12upstream/2.7.12
Change-Id: Id086dcc8e315c8ad61502768ef9b92372461e560 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 1bd570d..feac05a 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -75,6 +75,8 @@ class LocaleTime(object):
self.__calc_date_time()
if _getlang() != self.lang:
raise ValueError("locale changed during initialization")
+ if time.tzname != self.tzname or time.daylight != self.daylight:
+ raise ValueError("timezone changed during initialization")
def __pad(self, seq, front):
# Add '' to seq to either the front (is True), else the back.
@@ -159,15 +161,17 @@ class LocaleTime(object):
def __calc_timezone(self):
# Set self.timezone by using time.tzname.
- # Do not worry about possibility of time.tzname[0] == timetzname[1]
- # and time.daylight; handle that in strptime .
+ # Do not worry about possibility of time.tzname[0] == time.tzname[1]
+ # and time.daylight; handle that in strptime.
try:
time.tzset()
except AttributeError:
pass
- no_saving = frozenset(["utc", "gmt", time.tzname[0].lower()])
- if time.daylight:
- has_saving = frozenset([time.tzname[1].lower()])
+ self.tzname = time.tzname
+ self.daylight = time.daylight
+ no_saving = frozenset(["utc", "gmt", self.tzname[0].lower()])
+ if self.daylight:
+ has_saving = frozenset([self.tzname[1].lower()])
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
@@ -296,12 +300,15 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the format string."""
global _TimeRE_cache, _regex_cache
with _cache_lock:
- if _getlang() != _TimeRE_cache.locale_time.lang:
+ locale_time = _TimeRE_cache.locale_time
+ if (_getlang() != locale_time.lang or
+ time.tzname != locale_time.tzname or
+ time.daylight != locale_time.daylight):
_TimeRE_cache = TimeRE()
_regex_cache.clear()
+ locale_time = _TimeRE_cache.locale_time
if len(_regex_cache) > _CACHE_MAX_SIZE:
_regex_cache.clear()
- locale_time = _TimeRE_cache.locale_time
format_regex = _regex_cache.get(format)
if not format_regex:
try:
@@ -438,6 +445,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
week_starts_Mon = True if week_of_year_start == 0 else False
julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
week_starts_Mon)
+ if julian <= 0:
+ year -= 1
+ yday = 366 if calendar.isleap(year) else 365
+ julian += yday
# Cannot pre-calculate datetime_date() since can change in Julian
# calculation and thus could have different value for the day of the week
# calculation.