Revert "[3.13] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121144)" (GH-122408)

This reverts commit 009618f112.
This commit is contained in:
Serhiy Storchaka 2024-07-29 21:55:28 +03:00 committed by GitHub
parent 10cf7d6d00
commit 9f6f8790ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 172 deletions

View file

@ -204,17 +204,6 @@ def _format_offset(off, sep=':'):
s += '.%06d' % ss.microseconds
return s
_normalize_century = None
def _need_normalize_century():
global _normalize_century
if _normalize_century is None:
try:
_normalize_century = (
_time.strftime("%Y", (99, 1, 1, 0, 0, 0, 0, 1, 0)) != "0099")
except ValueError:
_normalize_century = True
return _normalize_century
# Correctly substitute for %z and %Z escapes in strftime formats.
def _wrap_strftime(object, format, timetuple):
# Don't call utcoffset() or tzname() unless actually needed.
@ -272,14 +261,6 @@ def _wrap_strftime(object, format, timetuple):
# strftime is going to have at this: escape %
Zreplace = s.replace('%', '%%')
newformat.append(Zreplace)
elif ch in 'YG' and object.year < 1000 and _need_normalize_century():
# Note that datetime(1000, 1, 1).strftime('%G') == '1000' so
# year 1000 for %G can go on the fast path.
if ch == 'G':
year = int(_time.strftime("%G", timetuple))
else:
year = object.year
push('{:04}'.format(year))
else:
push('%')
push(ch)