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

Class Calendar

Lib/calendar.py:194–327  ·  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

192
193
194class Calendar(object):
195 """
196 Base calendar class. This class doesn't do any formatting. It simply
197 provides data to subclasses.
198 """
199
200 def __init__(self, firstweekday=0):
201 self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday
202
203 def getfirstweekday(self):
204 return self._firstweekday % 7
205
206 def setfirstweekday(self, firstweekday):
207 self._firstweekday = firstweekday
208
209 firstweekday = property(getfirstweekday, setfirstweekday)
210
211 def iterweekdays(self):
212 """
213 Return an iterator for one week of weekday numbers starting with the
214 configured first one.
215 """
216 for i in range(self.firstweekday, self.firstweekday + 7):
217 yield i%7
218
219 def itermonthdates(self, year, month):
220 """
221 Return an iterator for one month. The iterator will yield datetime.date
222 values and will always iterate through complete weeks, so it will yield
223 dates outside the specified month.
224 """
225 for y, m, d in self.itermonthdays3(year, month):
226 yield datetime.date(y, m, d)
227
228 def itermonthdays(self, year, month):
229 """
230 Like itermonthdates(), but will yield day numbers. For days outside
231 the specified month the day number is 0.
232 """
233 day1, ndays = monthrange(year, month)
234 days_before = (day1 - self.firstweekday) % 7
235 yield from repeat(0, days_before)
236 yield from range(1, ndays + 1)
237 days_after = (self.firstweekday - day1 - ndays) % 7
238 yield from repeat(0, days_after)
239
240 def itermonthdays2(self, year, month):
241 """
242 Like itermonthdates(), but will yield (day number, weekday number)
243 tuples. For days outside the specified month the day number is 0.
244 """
245 for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday):
246 yield d, i % 7
247
248 def itermonthdays3(self, year, month):
249 """
250 Like itermonthdates(), but will yield (year, month, day) tuples. Can be
251 used for dates outside of datetime.date range.

Callers

nothing calls this directly

Calls 1

propertyClass · 0.85

Tested by

no test coverage detected