本文整理匯總了Python中calendar.day_abbr方法的典型用法代碼示例。如果您正苦於以下問題:Python calendar.day_abbr方法的具體用法?Python calendar.day_abbr怎麽用?Python calendar.day_abbr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calendar
的用法示例。
在下文中一共展示了calendar.day_abbr方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def __init__(self, wrap=True, year=None, month=None, day=None, ignore_case=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 ignore_case: Set to True to ignore case when mapping day names to set values
"""
SetBuilder.__init__(self,
names=calendar.day_abbr,
wrap=wrap,
ignore_case=ignore_case,
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
示例2: drawpoint
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def drawpoint(self, privatedata, sharedata, graph, point):
# draw a single day
x1_pt, y1_pt = graph.pos_pt((point["month"], 0), (point["day"], 0))
x2_pt, y2_pt = graph.pos_pt((point["month"], 1), (point["day"], 1))
p = path.rect_pt(x1_pt, y1_pt, x2_pt - x1_pt, y2_pt - y1_pt)
if point["weekday"] == calendar.day_abbr[-1]:
graph.stroke(p, [deco.filled([color.gray(0.8)])])
else:
graph.stroke(p)
graph.text_pt(x1_pt+3, y2_pt-3,
"%i %s" % (point["day"], point["weekday"]),
[text.valign.top])
if point["note"]:
graph.text_pt(x1_pt+3, y1_pt+3, point["note"], [text.size.tiny])
# create calendar data
示例3: __str__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def __str__(self):
d1 = self.start.astimezone(BRISBANE_TZ)
d2 = self.end.astimezone(BRISBANE_TZ)
start_str = (f"{day_abbr[d1.weekday()].upper()}"
+ f" {month_abbr[d1.month].upper()} {d1.day} {d1.hour}:{d1.minute:02}")
if (d1.month, d1.day) != (d2.month, d2.day):
end_str = (f"{day_abbr[d2.weekday()].upper()}"
+ f" {month_abbr[d2.month].upper()} {d2.day} {d2.hour}:{d2.minute:02}")
else:
end_str = f"{d2.hour}:{d2.minute:02}"
# Encode user-provided text to prevent certain characters
# being interpreted as slack commands.
summary_str = Event.encode_text(self.summary)
location_str = Event.encode_text(self.location)
if self.link is None:
return f"{'*' if self.source == 'UQCS' else ''}" \
f"`{summary_str}`" \
f"{'*' if self.source == 'UQCS' else ''}\n" \
f"*{start_str} - {end_str}* {'_(' + location_str + ')_' if location_str else ''}"
else:
return f"`<{self.link}|{summary_str}>`\n" \
f"*{start_str} - {end_str}* {'_(' + location_str + ')_' if location_str else ''}"
示例4: update_weather
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def update_weather(self):
forecast = forecastio.load_forecast(self.api_key, self.lat, self.lng)
daily = forecast.daily()
today_weekday = datetime.datetime.today().weekday()
max_temps = []
min_temps = []
daily_icons = []
for daily_data in daily.data:
daily_icons.append(daily_data.d['icon'])
max_temps.append(int(daily_data.d['temperatureMax']))
min_temps.append(int(daily_data.d['temperatureMin']))
for i in range(NUM_COLS):
day_element = self.window.FindElement('_DAY_' + str(i))
max_element = self.window.FindElement('_high_' + str(i))
min_element = self.window.FindElement('_low_' + str(i))
icon_element = self.window.FindElement('_icon_' + str(i))
day_element.Update(calendar.day_abbr[(today_weekday + i) % 7])
max_element.Update(max_temps[i])
min_element.Update(min_temps[i])
icon_element.Update(data=weather_icon_dict[daily_icons[i]][22:])
示例5: update_weather
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def update_weather(self):
forecast = forecastio.load_forecast(self.api_key, self.lat, self.lng)
daily = forecast.daily()
today_weekday = datetime.datetime.today().weekday()
max_temps = []
min_temps = []
daily_icons = []
for daily_data in daily.data:
daily_icons.append(daily_data.d['icon'])
max_temps.append(int(daily_data.d['temperatureMax']))
min_temps.append(int(daily_data.d['temperatureMin']))
for i in range(NUM_COLS):
day_element = self.window['-DAY-' + str(i)]
max_element = self.window['-high-' + str(i)]
min_element = self.window['-low-' + str(i)]
icon_element = self.window['-icon-' + str(i)]
day_element.update(calendar.day_abbr[(today_weekday + i) % 7])
max_element.update(max_temps[i])
min_element.update(min_temps[i])
icon_element.update(data=weather_icon_dict[daily_icons[i]][22:])
示例6: __init__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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
示例7: test_name
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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})
示例8: test_value
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
def test_value(self):
for i in range(0, len(calendar.day_abbr) - 1):
self.assertEqual(WeekdaySetBuilder().build(str(i)), {i})
示例9: test_L_wildcard
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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.assertEqual(tested_by_name, set())
self.assertEqual(tested_by_value, set())
else:
# in last week the set should contain the day
self.assertEqual(tested_by_name, {weekday})
self.assertEqual(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.assertEqual(builder.build(day_num_l), set())
self.assertEqual(builder.build(day_value_l), set())
weekday = (weekday + 1) % 7
示例10: test_weekday_numbered
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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.assertEqual(tested_by_name, {weekday})
tested_by_value = builder.build(str(weekday) + "#" + str(num))
self.assertEqual(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.assertEqual(tested_by_name, set())
tested_by_value = builder.build(str(other_weekday) + "#" + str(num))
self.assertEqual(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.assertEqual(tested_by_name, set())
tested_by_value = builder.build(str(weekday) + "#" + str(other_num))
self.assertEqual(tested_by_value, set())
weekday = (weekday + 1) % 7
示例11: __calc_weekday
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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
示例12: test_enumerateweekdays
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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)
示例13: test_days
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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)))
示例14: test_enumerate_weekdays
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import day_abbr [as 別名]
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)