本文整理匯總了Python中calendar.setfirstweekday方法的典型用法代碼示例。如果您正苦於以下問題:Python calendar.setfirstweekday方法的具體用法?Python calendar.setfirstweekday怎麽用?Python calendar.setfirstweekday使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calendar
的用法示例。
在下文中一共展示了calendar.setfirstweekday方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_setfirstweekday
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def test_setfirstweekday(self):
self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
self.assertRaises(ValueError, calendar.setfirstweekday, -1)
self.assertRaises(ValueError, calendar.setfirstweekday, 200)
orig = calendar.firstweekday()
calendar.setfirstweekday(calendar.SUNDAY)
self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
calendar.setfirstweekday(calendar.MONDAY)
self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
calendar.setfirstweekday(orig)
示例2: setUp
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def setUp(self):
self.oldfirstweekday = calendar.firstweekday()
calendar.setfirstweekday(self.firstweekday)
示例3: tearDown
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def tearDown(self):
calendar.setfirstweekday(self.oldfirstweekday)
示例4: get_calendar
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def get_calendar(year, month):
blank_week = [0, 0, 0, 0, 0, 0, 0]
calendar.setfirstweekday(calendar.SUNDAY)
c = calendar.monthcalendar(year, month)
if len(c) == 4:
c.append(blank_week)
if len(c) == 5:
c.append(blank_week)
return c
示例5: month_calendar
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def month_calendar(year, month, days, service):
calendar.setfirstweekday(calendar.SUNDAY)
month_calendar = calendar.monthcalendar(int(year), int(month))
month_name = calendar.month_name[int(month)]
month_href = reverse('services:month', args=(service.slug, year, month))
html = '<table><thead>'
html += '<tr><th colspan="7"><a href="{0}">{1}</a></th></tr>'.format(month_href, month_name)
html += '<tr><th>s</th><th>m</th><th>t</th><th>w</th><th>t</th><th>f</th><th>s</th></tr>'
html += '</thead><tbody>'
for week in month_calendar:
html += '<tr>'
for day in week:
if day == 0:
str_day = ''
else:
str_day = str(day).zfill(2)
if str_day in days:
day_href = reverse('services:day', args=(service.slug, year, month, str_day))
html += '<td><a href="{0}">{1}</a></td>'.format(day_href, str_day)
else:
html += '<td>{0}</td>'.format(str_day)
html += '</tr>'
html += '</tbody></table>'
return mark_safe(html)
示例6: setfirstweekday
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def setfirstweekday(weekday: int) -> None:
calendar.setfirstweekday(weekday)
示例7: test_setfirstweekday
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def test_setfirstweekday(self):
self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
self.assertRaises(ValueError, calendar.setfirstweekday, -1)
self.assertRaises(ValueError, calendar.setfirstweekday, 200)
orig = calendar.firstweekday()
calendar.setfirstweekday(calendar.SUNDAY)
self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
calendar.setfirstweekday(calendar.MONDAY)
self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
calendar.setfirstweekday(orig)
示例8: test_illegal_weekday_reported
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def test_illegal_weekday_reported(self):
with self.assertRaisesRegex(calendar.IllegalWeekdayError, '123'):
calendar.setfirstweekday(123)
示例9: __init__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import setfirstweekday [as 別名]
def __init__(self, month, year, indent_level, indent_style):
'x.__init__(...) initializes x'
calendar.setfirstweekday(calendar.SUNDAY)
matrix = calendar.monthcalendar(year, month)
self.__table = HTML_Table(len(matrix) + 1, 7, indent_level, indent_style)
for column, text in enumerate(calendar.day_name[-1:] + calendar.day_name[:-1]):
self.__table.mutate(0, column, '<b>%s</b>' % text)
for row, week in enumerate(matrix):
for column, day in enumerate(week):
if day:
self.__table.mutate(row + 1, column, '<b>%02d</b>\n<hr>\n' % day)
self.__weekday, self.__alldays = calendar.monthrange(year, month)
self.__weekday = ((self.__weekday + 1) % 7) + 6