本文整理匯總了Python中calendar.month_abbr方法的典型用法代碼示例。如果您正苦於以下問題:Python calendar.month_abbr方法的具體用法?Python calendar.month_abbr怎麽用?Python calendar.month_abbr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calendar
的用法示例。
在下文中一共展示了calendar.month_abbr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_data
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def handle_data(self,data):
ds = data.split(' ')
lds = len(ds)
if ds[lds-1].isdigit():
if lds == 3 or lds == 4:
day = str(ds[lds-3])
month = str(ds[lds-2])
year = str(ds[lds-1])
if len(day) == 1:
day = '0' + day
month = month[0:3]
monthNum = str(list(calendar.month_abbr).index(month))
if len(monthNum) == 1:
monthNum = '0' + monthNum
newDate = year +monthNum + day
self.dates.append(str(newDate))
示例2: month_or_day_formater
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def month_or_day_formater(month_or_day):
"""
Parameters
----------
month_or_day: str or int
must be one of the following:
(i) month: a three letter month abbreviation, e.g., 'Jan'.
(ii) day: an integer.
Returns
-------
numeric: str
a month of the form 'MM' or a day of the form 'DD'.
Note: returns None if:
(a) the input could not be mapped to a known month abbreviation OR
(b) the input was not an integer (i.e., a day).
"""
if month_or_day.replace(".", "") in filter(None, calendar.month_abbr):
to_format = strptime(month_or_day.replace(".", ""), "%b").tm_mon
elif month_or_day.strip().isdigit() and "." not in str(month_or_day):
to_format = int(month_or_day.strip())
else:
return None
return ("0" if to_format < 10 else "") + str(to_format)
示例3: __str__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_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: month_or_day_formater
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def month_or_day_formater(month_or_day):
"""
Parameters
----------
month_or_day: str or int
must be one of the following:
(i) month: a three letter month abbreviation, e.g., 'Jan'.
(ii) day: an integer.
Returns
-------
numeric: str
a month of the form 'MM' or a day of the form 'DD'.
Note: returns None if:
(a) the input could not be mapped to a known month abbreviation OR
(b) the input was not an integer (i.e., a day).
"""
if month_or_day.replace(".", "") in filter(None, calendar.month_abbr):
to_format = strptime(month_or_day.replace(".", ""),'%b').tm_mon
elif month_or_day.strip().isdigit() and "." not in str(month_or_day):
to_format = int(month_or_day.strip())
else:
return None
return ("0" if to_format < 10 else "") + str(to_format)
示例5: __init__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def __init__(self, config: Configuration, repository: GitRepository):
self.path = None
self.configuration = config
self.assets_path = os.path.join(HERE, self.assets_subdir)
self.git_repository_statistics = repository
self.has_tags_page = config.do_process_tags()
self._time_sampling_interval = "W"
self._do_generate_index_page = False
self._is_blame_data_allowed = False
self._max_orphaned_extensions_count = 0
templates_dir = os.path.join(HERE, self.templates_subdir)
self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
self.j2_env.filters['to_month_name_abr'] = lambda im: calendar.month_abbr[im]
self.j2_env.filters['to_weekday_name'] = lambda i: calendar.day_name[i]
self.j2_env.filters['to_ratio'] = lambda val, max_val: (float(val) / max_val) if max_val != 0 else 0
self.j2_env.filters['to_percentage'] = lambda val, max_val: (100 * float(val) / max_val) if max_val != 0 else 0
colors = colormaps.colormaps[self.configuration['colormap']]
self.j2_env.filters['to_heatmap'] = lambda val, max_val: "%d, %d, %d" % colors[int(float(val) / max_val * (len(colors) - 1))]
示例6: _parseReq
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def _parseReq(self, requnit, reqval):
''' Parse a non-day fixed value '''
assert reqval[0] != '='
try:
retn = []
for val in reqval.split(','):
if requnit == 'month':
if reqval[0].isdigit():
retn.append(int(reqval)) # must be a month (1-12)
else:
try:
retn.append(list(calendar.month_abbr).index(val.title()))
except ValueError:
retn.append(list(calendar.month_name).index(val.title()))
else:
retn.append(int(val))
except ValueError:
return None
return retn[0] if len(retn) == 1 else retn
示例7: _parse_req
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def _parse_req(requnit, reqval):
''' Parse a non-day fixed value '''
assert reqval[0] != '='
try:
retn = []
for val in reqval.split(','):
if requnit == 'month':
if reqval[0].isdigit():
retn.append(int(reqval)) # must be a month (1-12)
else:
try:
retn.append(list(calendar.month_abbr).index(val.title()))
except ValueError:
retn.append(list(calendar.month_name).index(val.title()))
else:
retn.append(int(val))
except ValueError:
return None
if not retn:
return None
return retn[0] if len(retn) == 1 else retn
示例8: __init__
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def __init__(self, wrap=True, ignore_case=True):
"""
Initializes set builder for month sets
:param wrap: Set to True to allow wrapping at last month of the year
:param ignore_case: Set to True to ignore case when mapping month names
"""
SetBuilder.__init__(self,
names=calendar.month_abbr[1:],
significant_name_characters=3,
offset=1,
ignore_case=ignore_case,
wrap=wrap)
示例9: test_name
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def test_name(self):
# abbreviations
for i, name in enumerate(calendar.month_abbr[1:]):
self.assertEqual(MonthSetBuilder().build(name), {i + 1})
self.assertEqual(MonthSetBuilder().build(name.lower()), {i + 1})
self.assertEqual(MonthSetBuilder().build(name.upper()), {i + 1})
# full names
for i, name in enumerate(calendar.month_name[1:]):
self.assertEqual(MonthSetBuilder().build(name), {i + 1})
self.assertEqual(MonthSetBuilder().build(name.lower()), {i + 1})
self.assertEqual(MonthSetBuilder().build(name.upper()), {i + 1})
示例10: __calc_month
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
示例11: test_to_datetime_format_microsecond
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def test_to_datetime_format_microsecond(self, cache):
# these are locale dependent
lang, _ = locale.getlocale()
month_abbr = calendar.month_abbr[4]
val = '01-{}-2011 00:00:01.978'.format(month_abbr)
format = '%d-%b-%Y %H:%M:%S.%f'
result = to_datetime(val, format=format, cache=cache)
exp = datetime.strptime(val, format)
assert result == exp
示例12: _get_timestamp
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def _get_timestamp():
now_month = int(datetime.datetime.now().strftime("%m"))
timestamp = calendar.month_abbr[now_month] + ' ' + datetime.datetime.now().strftime("%d %H:%M:%S")
return timestamp
示例13: get_timestamp
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def get_timestamp(date_str: str) -> datetime.timestamp:
month_to_int = dict((v, k) for k, v in enumerate(calendar.month_abbr))
_, month, day, _, _, year = date_str.split()
dt = datetime(year=int(year), month=month_to_int[month], day=int(day))
return datetime.timestamp(dt)
示例14: month2number
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def month2number(month):
"""Convert BibTeX or BibLateX month to numeric"""
if len(month) <= 2: # Assume a 1 or 2 digit numeric month has been given.
return month.zfill(2)
else: # Assume a textual month has been given.
month_abbr = month.strip()[:3].title()
try:
return str(list(calendar.month_abbr).index(month_abbr)).zfill(2)
except ValueError:
raise log.error("Please update the entry with a valid month.")
示例15: home
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import month_abbr [as 別名]
def home(request):
current = datetime.datetime.now().month
# there seems to be now way to derive a django query from another one
with connection.cursor() as cursor:
cursor.execute('''
SELECT COUNT(*), `subquery`.`mo`
FROM (SELECT `log_userconnection`.`user_id` AS `Col1`,
EXTRACT(MONTH FROM CONVERT_TZ(`log_userconnection`.`disconnected`, 'UTC', 'UTC')) AS `mo`,
COUNT(DISTINCT `log_userconnection`.`user_id`) AS `active`
FROM `log_userconnection`
GROUP BY `log_userconnection`.`user_id`,
`mo`
ORDER BY NULL) `subquery`
GROUP BY `subquery`.`mo`;
''')
query = cursor.fetchall()
query = {i[1]: i[0] for i in query if i[1] is not None}
population = []
for month in range(current, current - 12, -1):
if month < 1:
month += 12
value = 0 if month not in query else query[month]
population.append((calendar.month_abbr[month], value))
payload = {'population': population[::-1],
'punishments': Punishment.objects.count(),
'users': User.objects.count(),
'servers': Server.objects.count(),
'actions': LogModel.objects.count()}
return render(request, 'pages/home.pug', payload)