Return a named tuple containing ISO year, week number, and weekday. The first ISO week of the year is the (Mon-Sun) week containing the year's first Thursday; everything else derives from that. The first week is 1; Monday is 1 ... Sunday is 7. ISO calendar
(self)
| 1257 | return self.toordinal() % 7 or 7 |
| 1258 | |
| 1259 | def isocalendar(self): |
| 1260 | """Return a named tuple containing ISO year, week number, and weekday. |
| 1261 | |
| 1262 | The first ISO week of the year is the (Mon-Sun) week |
| 1263 | containing the year's first Thursday; everything else derives |
| 1264 | from that. |
| 1265 | |
| 1266 | The first week is 1; Monday is 1 ... Sunday is 7. |
| 1267 | |
| 1268 | ISO calendar algorithm taken from |
| 1269 | https://www.phys.uu.nl/~vgent/calendar/isocalendar.htm |
| 1270 | (used with permission) |
| 1271 | """ |
| 1272 | year = self._year |
| 1273 | week1monday = _isoweek1monday(year) |
| 1274 | today = _ymd2ord(self._year, self._month, self._day) |
| 1275 | # Internally, week and day have origin 0 |
| 1276 | week, day = divmod(today - week1monday, 7) |
| 1277 | if week < 0: |
| 1278 | year -= 1 |
| 1279 | week1monday = _isoweek1monday(year) |
| 1280 | week, day = divmod(today - week1monday, 7) |
| 1281 | elif week >= 52: |
| 1282 | if today >= _isoweek1monday(year+1): |
| 1283 | year += 1 |
| 1284 | week = 0 |
| 1285 | return _IsoCalendarDate(year, week+1, day+1) |
| 1286 | |
| 1287 | # Pickle support. |
| 1288 |