summaryrefslogtreecommitdiffstats
path: root/Lib/_pydatetime.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_pydatetime.py')
-rw-r--r--Lib/_pydatetime.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py
index 27cacb8..78432d4 100644
--- a/Lib/_pydatetime.py
+++ b/Lib/_pydatetime.py
@@ -215,6 +215,17 @@ def _need_normalize_century():
_normalize_century = True
return _normalize_century
+_supports_c99 = None
+def _can_support_c99():
+ global _supports_c99
+ if _supports_c99 is None:
+ try:
+ _supports_c99 = (
+ _time.strftime("%F", (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == "1900-01-01")
+ except ValueError:
+ _supports_c99 = False
+ return _supports_c99
+
# 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 +283,20 @@ 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.
+ # Note that datetime(1000, 1, 1).strftime('%G') == '1000' so
+ # year 1000 for %G can go on the fast path.
+ elif ((ch in 'YG' or ch in 'FC' and _can_support_c99()) and
+ object.year < 1000 and _need_normalize_century()):
if ch == 'G':
year = int(_time.strftime("%G", timetuple))
else:
year = object.year
- push('{:04}'.format(year))
+ if ch == 'C':
+ push('{:02}'.format(year // 100))
+ else:
+ push('{:04}'.format(year))
+ if ch == 'F':
+ push('-{:02}-{:02}'.format(*timetuple[1:3]))
else:
push('%')
push(ch)