MCPcopy Index your code
hub / github.com/python/cpython / Calendar

Class Calendar

Lib/calendar.py:213–346  ·  view source on GitHub ↗

Base calendar class. This class doesn't do any formatting. It simply provides data to subclasses.

Source from the content-addressed store, hash-verified

211
212
213class Calendar(object):
214 """
215 Base calendar class. This class doesn't do any formatting. It simply
216 provides data to subclasses.
217 """
218
219 def __init__(self, firstweekday=0):
220 self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday
221
222 def getfirstweekday(self):
223 return self._firstweekday % 7
224
225 def setfirstweekday(self, firstweekday):
226 self._firstweekday = firstweekday
227
228 firstweekday = property(getfirstweekday, setfirstweekday)
229
230 def iterweekdays(self):
231 """
232 Return an iterator for one week of weekday numbers starting with the
233 configured first one.
234 """
235 for i in range(self.firstweekday, self.firstweekday + 7):
236 yield i%7
237
238 def itermonthdates(self, year, month):
239 """
240 Return an iterator for one month. The iterator will yield datetime.date
241 values and will always iterate through complete weeks, so it will yield
242 dates outside the specified month.
243 """
244 for y, m, d in self.itermonthdays3(year, month):
245 yield datetime.date(y, m, d)
246
247 def itermonthdays(self, year, month):
248 """
249 Like itermonthdates(), but will yield day numbers. For days outside
250 the specified month the day number is 0.
251 """
252 day1, ndays = monthrange(year, month)
253 days_before = (day1 - self.firstweekday) % 7
254 yield from repeat(0, days_before)
255 yield from range(1, ndays + 1)
256 days_after = (self.firstweekday - day1 - ndays) % 7
257 yield from repeat(0, days_after)
258
259 def itermonthdays2(self, year, month):
260 """
261 Like itermonthdates(), but will yield (day number, weekday number)
262 tuples. For days outside the specified month the day number is 0.
263 """
264 for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday):
265 yield d, i % 7
266
267 def itermonthdays3(self, year, month):
268 """
269 Like itermonthdates(), but will yield (year, month, day) tuples. Can be
270 used for dates outside of datetime.date range.

Callers

nothing calls this directly

Calls 1

propertyClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…