(self)
| 1138 | self.assertEqual(dt2, dt - days) |
| 1139 | |
| 1140 | def test_strptime(self): |
| 1141 | inputs = [ |
| 1142 | # Basic valid cases |
| 1143 | (date(1998, 2, 3), '1998-02-03', '%Y-%m-%d'), |
| 1144 | (date(2004, 12, 2), '2004-12-02', '%Y-%m-%d'), |
| 1145 | |
| 1146 | # Edge cases: Leap year |
| 1147 | (date(2020, 2, 29), '2020-02-29', '%Y-%m-%d'), # Valid leap year date |
| 1148 | |
| 1149 | # bpo-34482: Handle surrogate pairs |
| 1150 | (date(2004, 12, 2), '2004-12\ud80002', '%Y-%m\ud800%d'), |
| 1151 | (date(2004, 12, 2), '2004\ud80012-02', '%Y\ud800%m-%d'), |
| 1152 | |
| 1153 | # Month/day variations |
| 1154 | (date(2004, 2, 1), '2004-02', '%Y-%m'), # No day provided |
| 1155 | (date(2004, 2, 1), '02-2004', '%m-%Y'), # Month and year swapped |
| 1156 | |
| 1157 | # Different day-month-year formats |
| 1158 | (date(2004, 12, 2), '02/12/2004', '%d/%m/%Y'), # Day/Month/Year |
| 1159 | (date(2004, 12, 2), '12/02/2004', '%m/%d/%Y'), # Month/Day/Year |
| 1160 | |
| 1161 | # Different separators |
| 1162 | (date(2023, 9, 24), '24.09.2023', '%d.%m.%Y'), # Dots as separators |
| 1163 | (date(2023, 9, 24), '24-09-2023', '%d-%m-%Y'), # Dashes |
| 1164 | (date(2023, 9, 24), '2023/09/24', '%Y/%m/%d'), # Slashes |
| 1165 | |
| 1166 | # Handling years with fewer digits |
| 1167 | (date(127, 2, 3), '0127-02-03', '%Y-%m-%d'), |
| 1168 | (date(99, 2, 3), '0099-02-03', '%Y-%m-%d'), |
| 1169 | (date(5, 2, 3), '0005-02-03', '%Y-%m-%d'), |
| 1170 | |
| 1171 | # Variations on ISO 8601 format |
| 1172 | (date(2023, 9, 25), '2023-W39-1', '%G-W%V-%u'), # ISO week date (Week 39, Monday) |
| 1173 | (date(2023, 9, 25), '2023-268', '%Y-%j'), # Year and day of the year (Julian) |
| 1174 | ] |
| 1175 | for expected, string, format in inputs: |
| 1176 | with self.subTest(string=string, format=format): |
| 1177 | got = date.strptime(string, format) |
| 1178 | self.assertEqual(expected, got) |
| 1179 | self.assertIs(type(got), date) |
| 1180 | |
| 1181 | def test_strptime_single_digit(self): |
| 1182 | # bpo-34903: Check that single digit dates are allowed. |
nothing calls this directly
no test coverage detected