我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用calendar.day_abbr()。
def __init__(self, wrap=True, year=None, month=None, day=None, ignorecase=True): """ :param wrap: Set to True to allow wrapping at last day of the week :param year: Year of week to build sets for, only required for date aware '#' and 'L' features in expressions :param month: Month of week to build sets for, only required for date aware '#' and 'L' features in expressions :param day: Day in week to build sets for, only required for date aware '#' and 'L' features in expressions :param ignorecase: Set to True to ignore case when mapping day names to set values """ SetBuilder.__init__(self, names=calendar.day_abbr, wrap=wrap, ignorecase=ignorecase, significant_name_characters=3, last_item_wildcard=WeekdaySetBuilder.LAST_DAY_WILDCARD) self._year = year self._month = month self._day = day self._first_weekday_in_month = None self._days_in_month = None self._post_custom_parsers = [self._parse_name_number, # name#num self._parse_value_number, # value#num self._parse_name_last_weekday, # nameL self._parse_value_last_weekday] # valueL
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
def test_name(self): for i, day_name in enumerate(calendar.day_abbr): self.assertEqual(WeekdaySetBuilder().build(day_name), {i}) for i, day_name in enumerate(calendar.day_name): self.assertEqual(WeekdaySetBuilder().build(day_name), {i})
def test_value(self): for i in range(0, len(calendar.day_abbr) - 1): self.assertEqual(WeekdaySetBuilder().build(str(i)), {i})
def test_L_wildcard(self): for year in [2016, 2017]: for month in range(1, 13): weekday, days_in_month = calendar.monthrange(year, month) for tested_on_day in range(1, days_in_month + 1): builder = WeekdaySetBuilder(year=year, month=month, day=tested_on_day) # test by name of weekday day_num_l = calendar.day_abbr[weekday] + "L" tested_by_name = builder.build(day_num_l) # test by number of weekday day_value_l = str(weekday) + "L" tested_by_value = builder.build(day_value_l) # everything before last week should be empty set if tested_on_day <= (days_in_month - 7): self.assertEquals(tested_by_name, set()) self.assertEquals(tested_by_value, set()) else: # in last week the set should contain the day self.assertEquals(tested_by_name, {weekday}) self.assertEquals(tested_by_value, {weekday}) # test if other weekdays on that day return empty set for d in range(0, 6): if d != weekday: day_num_l = calendar.day_abbr[d] + "L" day_value_l = str(d) + "L" self.assertEquals(builder.build(day_num_l), set()) self.assertEqual(builder.build(day_value_l), set()) weekday = (weekday + 1) % 7
def test_weekday_numbered(self): for year in [2016, 2017]: for month in range(1, 13): weekday, days_in_month = calendar.monthrange(year, month) for day in range(1, days_in_month + 1): num = int((day - 1) / 7) + 1 builder = WeekdaySetBuilder(year=year, month=month, day=day) tested_by_name = builder.build(calendar.day_abbr[weekday] + "#" + str(num)) self.assertEquals(tested_by_name, {weekday}) tested_by_value = builder.build(str(weekday) + "#" + str(num)) self.assertEquals(tested_by_value, {weekday}) for other_weekday in range(0, 7): if other_weekday != weekday: tested_by_name = builder.build(calendar.day_abbr[other_weekday] + "#" + str(num)) self.assertEquals(tested_by_name, set()) tested_by_value = builder.build(str(other_weekday) + "#" + str(num)) self.assertEquals(tested_by_value, set()) for other_num in range(1, 6): if num != other_num: tested_by_name = builder.build(calendar.day_abbr[weekday] + "#" + str(other_num)) self.assertEquals(tested_by_name, set()) tested_by_value = builder.build(str(weekday) + "#" + str(other_num)) self.assertEquals(tested_by_value, set()) weekday = (weekday + 1) % 7
def GetTime(self): """ Get the time this robot is set to Returns: A dictionary with the time of day and day of week (dict) """ result = self._PostToRobot("get", "time") day_idx = [idx for idx, day in enumerate(calendar.day_abbr) if day.lower() == result["d"]][0] return { "time" : datetime.time(result["h"], result["m"]), "weekday" : calendar.day_name[day_idx] }
def test_enumerateweekdays(self): self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10) self.assertRaises(IndexError, calendar.day_name.__getitem__, 10) self.assertEqual(len([d for d in calendar.day_abbr]), 7)
def test_days(self): for attr in "day_name", "day_abbr": value = getattr(calendar, attr) self.assertEqual(len(value), 7) self.assertEqual(len(value[:]), 7) # ensure they're all unique self.assertEqual(len(set(value)), 7) # verify it "acts like a sequence" in two forms of iteration self.assertEqual(value[::-1], list(reversed(value)))
def test_enumerate_weekdays(self): self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10) self.assertRaises(IndexError, calendar.day_name.__getitem__, 10) self.assertEqual(len([d for d in calendar.day_abbr]), 7)
def generate_cal_widgets(self): cal_list = [] for i in calendar.day_abbr: self.cal_layout.add_widget(WeekdayLabel(text=i[0].upper())) for i in range(6 * 7): # 6 weeks, 7 days a week db = DayButton(owner=self) cal_list.append(db) self.cal_layout.add_widget(db) self.cal_list = cal_list
def strftest1(self, now): if support.verbose: print("strftime test for", time.ctime(now)) now = self.now # Make sure any characters that could be taken as regex syntax is # escaped in escapestr() expectations = ( ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'), ('%A', calendar.day_name[now[6]], 'full weekday name'), ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'), ('%B', calendar.month_name[now[1]], 'full month name'), # %c see below ('%d', '%02d' % now[2], 'day of month as number (00-31)'), ('%H', '%02d' % now[3], 'hour (00-23)'), ('%I', '%02d' % self.clock12, 'hour (01-12)'), ('%j', '%03d' % now[7], 'julian day (001-366)'), ('%m', '%02d' % now[1], 'month as number (01-12)'), ('%M', '%02d' % now[4], 'minute, (00-59)'), ('%p', self.ampm, 'AM or PM as appropriate'), ('%S', '%02d' % now[5], 'seconds of current time (00-60)'), ('%U', '%02d' % ((now[7] + self.jan1[6])//7), 'week number of the year (Sun 1st)'), ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'), ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7), 'week number of the year (Mon 1st)'), # %x see below ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), ('%y', '%02d' % (now[0]%100), 'year without century'), ('%Y', '%d' % now[0], 'year with century'), # %Z see below ('%%', '%', 'single percent sign'), ) for e in expectations: # musn't raise a value error try: result = time.strftime(e[0], now) except ValueError as error: self.fail("strftime '%s' format gave error: %s" % (e[0], error)) if re.match(escapestr(e[1], self.ampm), result): continue if not result or result[0] == '%': self.fail("strftime does not support standard '%s' format (%s)" % (e[0], e[2])) else: self.fail("Conflict for %s (%s): expected %s, but got %s" % (e[0], e[2], e[1], result))
def strftest1(self, now): if test_support.verbose: print "strftime test for", time.ctime(now) now = self.now # Make sure any characters that could be taken as regex syntax is # escaped in escapestr() expectations = ( ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'), ('%A', calendar.day_name[now[6]], 'full weekday name'), ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'), ('%B', calendar.month_name[now[1]], 'full month name'), # %c see below ('%d', '%02d' % now[2], 'day of month as number (00-31)'), ('%H', '%02d' % now[3], 'hour (00-23)'), ('%I', '%02d' % self.clock12, 'hour (01-12)'), ('%j', '%03d' % now[7], 'julian day (001-366)'), ('%m', '%02d' % now[1], 'month as number (01-12)'), ('%M', '%02d' % now[4], 'minute, (00-59)'), ('%p', self.ampm, 'AM or PM as appropriate'), ('%S', '%02d' % now[5], 'seconds of current time (00-60)'), ('%U', '%02d' % ((now[7] + self.jan1[6])//7), 'week number of the year (Sun 1st)'), ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'), ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7), 'week number of the year (Mon 1st)'), # %x see below ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), ('%y', '%02d' % (now[0]%100), 'year without century'), ('%Y', '%d' % now[0], 'year with century'), # %Z see below ('%%', '%', 'single percent sign'), ) for e in expectations: # musn't raise a value error try: result = time.strftime(e[0], now) except ValueError, error: self.fail("strftime '%s' format gave error: %s" % (e[0], error)) if re.match(escapestr(e[1], self.ampm), result): continue if not result or result[0] == '%': self.fail("strftime does not support standard '%s' format (%s)" % (e[0], e[2])) else: self.fail("Conflict for %s (%s): expected %s, but got %s" % (e[0], e[2], e[1], result))