本文整理汇总了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