本文整理汇总了Python中pycalendar.datetime.DateTime.getYear方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.getYear方法的具体用法?Python DateTime.getYear怎么用?Python DateTime.getYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycalendar.datetime.DateTime
的用法示例。
在下文中一共展示了DateTime.getYear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getMonthTable
# 需要导入模块: from pycalendar.datetime import DateTime [as 别名]
# 或者: from pycalendar.datetime.DateTime import getYear [as 别名]
def getMonthTable(month, year, weekstart, table, today_index):
from pycalendar.datetime import DateTime
# Get today
today = DateTime.getToday(None)
today_index = [-1, -1]
# Start with empty table
table = []
# Determine first weekday in month
temp = DateTime(year, month, 1, 0)
row = -1
initial_col = temp.getDayOfWeek() - weekstart
if initial_col < 0:
initial_col += 7
col = initial_col
# Counters
max_day = daysInMonth(month, year)
# Fill up each row
for day in range(1, max_day + 1):
# Insert new row if we are at the start of a row
if (col == 0) or (day == 1):
table.extend([0] * 7)
row += 1
# Set the table item to the current day
table[row][col] = packDate(temp.getYear(), temp.getMonth(), day)
# Check on today
if (temp.getYear() == today.getYear()) and (temp.getMonth() == today.getMonth()) and (day == today.getDay()):
today_index = [row, col]
# Bump column (modulo 7)
col += 1
if (col > 6):
col = 0
# Add next month to remainder
temp.offsetMonth(1)
if col != 0:
day = 1
while col < 7:
table[row][col] = packDate(temp.getYear(), temp.getMonth(), -day)
# Check on today
if (temp.getYear() == today.getYear()) and (temp.getMonth() == today.getMonth()) and (day == today.getDay()):
today_index = [row, col]
day += 1
col += 1
# Add previous month to start
temp.offsetMonth(-2)
if (initial_col != 0):
day = daysInMonth(temp.getMonth(), temp.getYear())
back_col = initial_col - 1
while(back_col >= 0):
table[row][back_col] = packDate(temp.getYear(), temp.getMonth(), -day)
# Check on today
if (temp.getYear() == today.getYear()) and (temp.getMonth() == today.getMonth()) and (day == today.getDay()):
today_index = [0, back_col]
back_col -= 1
day -= 1
return table, today_index