Skip to content

Commit 11e0218

Browse files
author
marat
committed
Fix tests for IOS and add docs
1 parent 8d16901 commit 11e0218

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Doc/library/datetime.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2762,11 +2762,17 @@ Notes:
27622762
interchangeable.
27632763

27642764
(9)
2765+
When used with the :meth:`~.datetime.strftime` method, the leading zero is optional
2766+
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
2767+
``%W``, ``%V`` and ``%y`` (except that on Apple platforms, ``%y`` still requires a leading zero).
2768+
Use the ``%-`` flag to produce non-zero-padded output (e.g. ``%-d``).
2769+
2770+
(10)
27652771
When used with the :meth:`~.datetime.strptime` method, the leading zero is optional
27662772
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
27672773
``%W``, and ``%V``. Format ``%y`` does require a leading zero.
27682774

2769-
(10)
2775+
(11)
27702776
When parsing a month and day using :meth:`~.datetime.strptime`, always
27712777
include a year in the format. If the value you need to parse lacks a year,
27722778
append an explicit dummy leap year. Otherwise your code will raise an

Lib/test/datetimetester.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,13 +1590,15 @@ def test_strftime(self):
15901590
self.assertEqual(t.strftime('x'*1000), 'x'*1000) # SF bug #1556784
15911591

15921592
# SF bug #137165
1593-
if platform.system() == 'Darwin':
1593+
if platform.system() in ('Darwin', 'iOS'):
15941594
self.assertEqual(t.strftime("m:%-m d:%-d y:%-y"), "m:3 d:2 y:05")
15951595
else:
15961596
if platform.system() == 'Windows':
15971597
self.assertEqual(t.strftime("m:%#m d:%#d y:%#y"), "m:3 d:2 y:5")
15981598
self.assertEqual(t.strftime("m:%-m d:%-d y:%-y"), "m:3 d:2 y:5")
15991599

1600+
self.assertEqual(t.strftime("%-j. %-U. %-W. %-V."), "61. 9. 9. 9.")
1601+
16001602
self.assertRaises(TypeError, t.strftime) # needs an arg
16011603
self.assertRaises(TypeError, t.strftime, "one", "two") # too many args
16021604
self.assertRaises(TypeError, t.strftime, 42) # arg wrong type

0 commit comments

Comments
 (0)