当前位置: 首页>>代码示例>>Python>>正文


Python DateTime.offsetMonth方法代码示例

本文整理汇总了Python中pycalendar.datetime.DateTime.offsetMonth方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.offsetMonth方法的具体用法?Python DateTime.offsetMonth怎么用?Python DateTime.offsetMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycalendar.datetime.DateTime的用法示例。


在下文中一共展示了DateTime.offsetMonth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getMonthTable

# 需要导入模块: from pycalendar.datetime import DateTime [as 别名]
# 或者: from pycalendar.datetime.DateTime import offsetMonth [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
开发者ID:eventable,项目名称:PyCalendar,代码行数:72,代码来源:utils.py


注:本文中的pycalendar.datetime.DateTime.offsetMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。