本文整理汇总了Python中calendar.Calendar.monthdays2calendar方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.monthdays2calendar方法的具体用法?Python Calendar.monthdays2calendar怎么用?Python Calendar.monthdays2calendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.monthdays2calendar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_month
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def get_month(y, m):
"""
Return list of month's weeks, which day
is a turple (<month day number>, <weekday number>)
"""
cal = Calendar()
month = cal.monthdays2calendar(y, m)
# Add additional num to every day which mark from
# this or from other day that day numer
for week in range(len(month)):
for day in range(len(month[week])):
_day = month[week][day]
if _day[0] == 0:
this = 0
else:
this = 1
_day = (_day[0], _day[1], this)
month[week][day] = _day
# Days numbers of days from preious and next monthes
# marked as 0 (zero), replace it with correct numbers
# If month include 4 weeks it hasn't any zero
if len(month) == 4:
return month
quater = calc_quarter(y, m)
# Zeros in first week
fcount = 0
for i in month[0]:
if i[0] == 0:
fcount += 1
# Zeros in last week
lcount = 0
for i in month[-1]:
if i[0] == 0:
lcount += 1
if fcount:
# Last day of prev month
n = monthrange(quater[0][0], quater[0][1])[1]
for i in range(fcount):
month[0][i] = (n - (fcount - 1 - i), i, 0)
if lcount:
# First day of next month
n = 1
for i in range(lcount):
month[-1][-lcount + i] = (n + i, 7 - lcount + i, 0)
return month
示例2: find_mondays
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def find_mondays(year, month):
cal = Calendar()
mondays = list()
for week in cal.monthdays2calendar(year, month):
for day in week:
(monthday, weekday) = day
if (weekday == 1 and monthday > 0):
mondays.append(datetime.date(year=year,
month=month,
day=monthday))
return mondays
示例3: calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def calendar(tasks, date_obj=date.today()):
month, year = date_obj.month, date_obj.year
tasks = tasks
dates = Calendar()
weeks = [process_week(week, month, year) for week in
dates.monthdays2calendar(year, month)]
weeks = [check_tasks(week, tasks) for week in weeks]
return {
'weeks': weeks,
'date_obj': date_obj,
}
示例4: get_month_wireframe
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def get_month_wireframe(year, month, day):
"""
Utility function for getting the layout of month days
"""
year, month, day = int(year), int(month), int(day)
cal = Calendar()
monthly_days = cal.monthdays2calendar(year, month)
return {
'monthly_days': monthly_days,
'year': year,
'month': MONTHS[month],
'today': day,
}
示例5: get_week_wireframe
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def get_week_wireframe(year, month, day):
"""
Utility function for returning the current week
"""
year, month, day = int(year), int(month), int(day)
cal = Calendar()
monthly_days = cal.monthdays2calendar(year, month)
current_week = None
for week in monthly_days:
if [i for i, v in enumerate(week) if v[0] == day]:
current_week = week
return {
'week': current_week,
'year': year,
'month': MONTHS[month],
'today': day,
}
示例6: horas_semana
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdays2calendar [as 别名]
def horas_semana(self, ano, mes, semana):
total = timedelta(hours=0, minutes=0)
calendario = Calendar()
listasemana = calendario.monthdays2calendar(year=ano, month=mes)
try:
for dia in listasemana[semana]:
if not dia[0] == 0:
diatrabalhado = self.diatrabalho_set.filter(data=datetime(year=ano, month=mes, day=dia[0]))
if diatrabalhado:
diatrabalhado = diatrabalhado[0]
total += diatrabalhado.horas_trabalhadas()
return total
except IndexError:
return timedelta(hours=0, minutes=0)