我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用calendar.setfirstweekday()。
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
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)
def setUp(self): self.oldfirstweekday = calendar.firstweekday() calendar.setfirstweekday(self.firstweekday)
def tearDown(self): calendar.setfirstweekday(self.oldfirstweekday)
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)
def test_illegal_weekday_reported(self): with self.assertRaisesRegex(calendar.IllegalWeekdayError, '123'): calendar.setfirstweekday(123)
def chartSimpleCalendar(self, dev, p_dict, k_dict, return_queue): """""" log = {'Threaddebug': [], 'Debug': [], 'Info': [], 'Warning': [], 'Critical': []} try: if self.verboseLogging: log['Debug'].append(u"{0:<19}{1}".format("p_dict: ", [(k, v) for (k, v) in sorted(p_dict.items())])) log['Debug'].append(u"{0:<19}{1}".format("k_dict: ", [(k, v) for (k, v) in sorted(k_dict.items())])) import calendar today = dt.datetime.today() calendar.setfirstweekday(int(dev.pluginProps['firstDayOfWeek'])) cal = calendar.month(today.year, today.month) ax = self.chartMakeFigure(350, 250, p_dict) ax.text(0, 1, cal, transform=ax.transAxes, color=p_dict['fontColor'], fontname='Andale Mono', fontsize=dev.pluginProps['fontSize'], backgroundcolor=p_dict['faceColor'], bbox=dict(pad=3), **k_dict['k_calendar']) ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) ax.axis('off') # uncomment this line to hide the box if p_dict['fileName'] != '': plt.savefig(u'{0}{1}'.format(p_dict['chartPath'], p_dict['fileName']), **k_dict['k_plot_fig']) plt.clf() plt.close('all') return_queue.put({'Error': False, 'Log': log, 'Message': 'updated successfully.', 'Name': dev.name}) except UnicodeEncodeError as sub_error: return_queue.put({'Error': True, 'Log': log, 'Message': sub_error, 'Name': dev.name}) except Exception as sub_error: return_queue.put({'Error': True, 'Log': log, 'Message': sub_error, 'Name': dev.name})
def calendar_sql(gid, pid, year, month, show_subtasks): if show_subtasks: q = DBS.query(Task).filter_by(gid=gid, pid=pid) else: q = DBS.query(Task).filter_by(gid=gid, pid=pid, ptid=0) rs = q.all() task_d = {} for r in rs: if str(r.due_date) not in task_d: task_d[str(r.due_date)] = r.name else: task_d[str(r.due_date)] += "\n" + r.name calendar.setfirstweekday(6) calendar_a = calendar.monthcalendar(year, month) for week in range(len(calendar_a)): for day in range(7): date_num = calendar_a[week][day] if date_num == 0: calendar_a[week][day] = {'date_num': 0, 'tasks': ""} # TODO: show out of month days and tasks continue str_date = datetime.date(year, month, date_num)\ .strftime('%Y-%m-%d') calendar_a[week][day] = {'date_num': date_num, 'tasks': task_d[str_date] if str_date in task_d else ''} return calendar_a