MCPcopy Index your code
hub / github.com/RustPython/RustPython / isocalendar

Method isocalendar

Lib/_pydatetime.py:1244–1270  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1242 return self.toordinal() % 7 or 7
1243
1244 def isocalendar(self):
1245 """Return a named tuple containing ISO year, week number, and weekday.
1246
1247 The first ISO week of the year is the (Mon-Sun) week
1248 containing the year's first Thursday; everything else derives
1249 from that.
1250
1251 The first week is 1; Monday is 1 ... Sunday is 7.
1252
1253 ISO calendar algorithm taken from
1254 https://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
1255 (used with permission)
1256 """
1257 year = self._year
1258 week1monday = _isoweek1monday(year)
1259 today = _ymd2ord(self._year, self._month, self._day)
1260 # Internally, week and day have origin 0
1261 week, day = divmod(today - week1monday, 7)
1262 if week < 0:
1263 year -= 1
1264 week1monday = _isoweek1monday(year)
1265 week, day = divmod(today - week1monday, 7)
1266 elif week >= 52:
1267 if today >= _isoweek1monday(year+1):
1268 year += 1
1269 week = 0
1270 return _IsoCalendarDate(year, week+1, day+1)
1271
1272 # Pickle support.
1273

Callers 4

test_isocalendarMethod · 0.80
test_iso_long_yearsMethod · 0.80
test_fromisocalendarMethod · 0.80

Calls 3

_isoweek1mondayFunction · 0.85
_ymd2ordFunction · 0.85
divmodFunction · 0.50

Tested by 4

test_isocalendarMethod · 0.64
test_iso_long_yearsMethod · 0.64
test_fromisocalendarMethod · 0.64