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


Python calendar.monthcalendar方法代码示例

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


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

示例1: _week_day

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def _week_day(date, week, weekday):
    """
    特定の月の第1月曜日などを返します。
    """
    if week < 1 or week > 5:
        return None

    if weekday < 1 or weekday > 7:
        return None

    lines = calendar.monthcalendar(date.year, date.month)

    days = []
    for line in lines:
        if line[weekday - 1] == 0:
            continue

        days.append(line[weekday - 1])

    return datetime.date(date.year, date.month, days[week - 1]) 
开发者ID:Lalcs,项目名称:jpholiday,代码行数:22,代码来源:utils.py

示例2: check_weeks

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def check_weeks(self, year, month, weeks):
        cal = calendar.monthcalendar(year, month)
        self.assertEqual(len(cal), len(weeks))
        for i in xrange(len(weeks)):
            self.assertEqual(weeks[i], sum(day != 0 for day in cal[i])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_calendar.py

示例3: get_calendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def get_calendar(year, month):
    blank_week = [0, 0, 0, 0, 0, 0, 0]
    calendar.setfirstweekday(calendar.SUNDAY)
    c = calendar.monthcalendar(year, month)
    if len(c) == 4:
        c.append(blank_week)
    if len(c) == 5:
        c.append(blank_week)
    return c 
开发者ID:vitorfs,项目名称:woid,代码行数:11,代码来源:calendar_helpers.py

示例4: month_calendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def month_calendar(year, month, days, service):
    calendar.setfirstweekday(calendar.SUNDAY)
    month_calendar = calendar.monthcalendar(int(year), int(month))

    month_name = calendar.month_name[int(month)]
    month_href = reverse('services:month', args=(service.slug, year, month))

    html = '<table><thead>'
    html += '<tr><th colspan="7"><a href="{0}">{1}</a></th></tr>'.format(month_href, month_name)
    html += '<tr><th>s</th><th>m</th><th>t</th><th>w</th><th>t</th><th>f</th><th>s</th></tr>'
    html += '</thead><tbody>'
    for week in month_calendar:
        html += '<tr>'
        for day in week:
            if day == 0:
                str_day = ''
            else:
                str_day = str(day).zfill(2)
            if str_day in days:
                day_href = reverse('services:day', args=(service.slug, year, month, str_day))
                html += '<td><a href="{0}">{1}</a></td>'.format(day_href, str_day)
            else:
                html += '<td>{0}</td>'.format(str_day)
        html += '</tr>'
    html += '</tbody></table>'
    return mark_safe(html) 
开发者ID:vitorfs,项目名称:woid,代码行数:28,代码来源:calendar_helpers.py

示例5: check_weeks

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def check_weeks(self, year, month, weeks):
        cal = calendar.monthcalendar(year, month)
        self.assertEqual(len(cal), len(weeks))
        for i in range(len(weeks)):
            self.assertEqual(weeks[i], sum(day != 0 for day in cal[i])) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_calendar.py

示例6: create_calendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def create_calendar(year=None,month=None):
    """
    Create an inline keyboard with the provided year and month
    :param int year: Year to use in the calendar, if None the current year is used.
    :param int month: Month to use in the calendar, if None the current month is used.
    :return: Returns the InlineKeyboardMarkup object with the calendar.
    """
    now = datetime.datetime.now()
    if year == None: year = now.year
    if month == None: month = now.month
    data_ignore = create_callback_data("IGNORE", year, month, 0)
    keyboard = []
    #First row - Month and Year
    row=[]
    row.append(InlineKeyboardButton(calendar.month_name[month]+" "+str(year),callback_data=data_ignore))
    keyboard.append(row)
    #Second row - Week Days
    row=[]
    for day in ["Mo","Tu","We","Th","Fr","Sa","Su"]:
        row.append(InlineKeyboardButton(day,callback_data=data_ignore))
    keyboard.append(row)

    my_calendar = calendar.monthcalendar(year, month)
    for week in my_calendar:
        row=[]
        for day in week:
            if(day==0):
                row.append(InlineKeyboardButton(" ",callback_data=data_ignore))
            else:
                row.append(InlineKeyboardButton(str(day),callback_data=create_callback_data("DAY",year,month,day)))
        keyboard.append(row)
    #Last row - Buttons
    row=[]
    row.append(InlineKeyboardButton("<",callback_data=create_callback_data("PREV-MONTH",year,month,day)))
    row.append(InlineKeyboardButton(" ",callback_data=data_ignore))
    row.append(InlineKeyboardButton(">",callback_data=create_callback_data("NEXT-MONTH",year,month,day)))
    keyboard.append(row)

    return InlineKeyboardMarkup(keyboard) 
开发者ID:unmonoqueteclea,项目名称:calendar-telegram,代码行数:41,代码来源:telegramcalendar.py

示例7: get_last_message_id

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def get_last_message_id(messages_ids, M, last_wanted):
    for i in messages_ids:
        try:
            message_lines = M.top( str(i), '0')[1]
        except poplib.error_proto:
            print 'Problem in pop top call...'
            continue

        for line in message_lines:
            if line.startswith('Date:'):

                date_hdr = line.partition('Date: ')[2]
                # print date_hdr
                try:
                    (y, month, d, \
                     h, min, sec, \
                     _, _, _, tzoffset) = parsedate_tz(date_hdr)
                except (TypeError): continue
                except (ValueError): continue

                # Python range builtin ?
                if month < 0 or month > 12: continue
                max_day_per_month = max(calendar.monthcalendar(y, month)[-1])
                if d <= 0 or d > max_day_per_month: continue
                if h < 0 or h > 23: continue
                if min < 0 or min > 59: continue

                date = datetime.datetime(y, month, d, h, min, sec)

                print date
                if date < last_wanted:
                    return i 
开发者ID:ActiveState,项目名称:code,代码行数:34,代码来源:recipe-576922.py

示例8: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def __init__(self, month, year, indent_level, indent_style):
        'x.__init__(...) initializes x'
        calendar.setfirstweekday(calendar.SUNDAY)
        matrix = calendar.monthcalendar(year, month)
        self.__table = HTML_Table(len(matrix) + 1, 7, indent_level, indent_style)
        for column, text in enumerate(calendar.day_name[-1:] + calendar.day_name[:-1]):
            self.__table.mutate(0, column, '<b>%s</b>' % text)
        for row, week in enumerate(matrix):
            for column, day in enumerate(week):
                if day:
                    self.__table.mutate(row + 1, column, '<b>%02d</b>\n<hr>\n' % day)
        self.__weekday, self.__alldays = calendar.monthrange(year, month)
        self.__weekday = ((self.__weekday + 1) % 7) + 6 
开发者ID:ActiveState,项目名称:code,代码行数:15,代码来源:recipe-496862.py

示例9: _first_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def _first_of_month(self, day_of_week):
        """
        Modify to the first occurrence of a given day of the week
        in the current month. If no day_of_week is provided,
        modify to the first day of the month. Use the supplied consts
        to indicate the desired day_of_week, ex. pendulum.MONDAY.

        :type day_of_week: int

        :rtype: Date
        """
        dt = self

        if day_of_week is None:
            return dt.set(day=1)

        month = calendar.monthcalendar(dt.year, dt.month)

        calendar_day = (day_of_week - 1) % 7

        if month[0][calendar_day] > 0:
            day_of_month = month[0][calendar_day]
        else:
            day_of_month = month[1][calendar_day]

        return dt.set(day=day_of_month) 
开发者ID:sdispater,项目名称:pendulum,代码行数:28,代码来源:date.py

示例10: _last_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def _last_of_month(self, day_of_week=None):
        """
        Modify to the last occurrence of a given day of the week
        in the current month. If no day_of_week is provided,
        modify to the last day of the month. Use the supplied consts
        to indicate the desired day_of_week, ex. pendulum.MONDAY.

        :type day_of_week: int or None

        :rtype: Date
        """
        dt = self

        if day_of_week is None:
            return dt.set(day=self.days_in_month)

        month = calendar.monthcalendar(dt.year, dt.month)

        calendar_day = (day_of_week - 1) % 7

        if month[-1][calendar_day] > 0:
            day_of_month = month[-1][calendar_day]
        else:
            day_of_month = month[-2][calendar_day]

        return dt.set(day=day_of_month) 
开发者ID:sdispater,项目名称:pendulum,代码行数:28,代码来源:date.py

示例11: _first_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def _first_of_month(self, day_of_week):
        """
        Modify to the first occurrence of a given day of the week
        in the current month. If no day_of_week is provided,
        modify to the first day of the month. Use the supplied consts
        to indicate the desired day_of_week, ex. DateTime.MONDAY.

        :type day_of_week: int

        :rtype: DateTime
        """
        dt = self.start_of("day")

        if day_of_week is None:
            return dt.set(day=1)

        month = calendar.monthcalendar(dt.year, dt.month)

        calendar_day = (day_of_week - 1) % 7

        if month[0][calendar_day] > 0:
            day_of_month = month[0][calendar_day]
        else:
            day_of_month = month[1][calendar_day]

        return dt.set(day=day_of_month) 
开发者ID:sdispater,项目名称:pendulum,代码行数:28,代码来源:datetime.py

示例12: _last_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def _last_of_month(self, day_of_week=None):
        """
        Modify to the last occurrence of a given day of the week
        in the current month. If no day_of_week is provided,
        modify to the last day of the month. Use the supplied consts
        to indicate the desired day_of_week, ex. DateTime.MONDAY.

        :type day_of_week: int or None

        :rtype: DateTime
        """
        dt = self.start_of("day")

        if day_of_week is None:
            return dt.set(day=self.days_in_month)

        month = calendar.monthcalendar(dt.year, dt.month)

        calendar_day = (day_of_week - 1) % 7

        if month[-1][calendar_day] > 0:
            day_of_month = month[-1][calendar_day]
        else:
            day_of_month = month[-2][calendar_day]

        return dt.set(day=day_of_month) 
开发者ID:sdispater,项目名称:pendulum,代码行数:28,代码来源:datetime.py

示例13: get_nth_kday_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def get_nth_kday_of_month(gday, gmonth, gyear):
    r"""Convert Gregorian date to RDate format.

    Parameters
    ----------
    gday : int
        Gregorian day.
    gmonth : int
        Gregorian month.
    gyear : int
        Gregorian year.

    Returns
    -------
    nth : int
        Ordinal number of a given day's occurrence within the month,
        for example, the third Friday of the month.
    """

    this_month = calendar.monthcalendar(gyear, gmonth)
    nth_kday_tuple = next(((i, e.index(gday)) for i, e in enumerate(this_month) if gday in e), None)
    tuple_row = nth_kday_tuple[0]
    tuple_pos = nth_kday_tuple[1]
    nth = tuple_row + 1
    if tuple_row > 0 and this_month[0][tuple_pos] == 0:
        nth -= 1
    return nth


#
# Function get_rdate
# 
开发者ID:ScottfreeLLC,项目名称:AlphaPy,代码行数:34,代码来源:calendrical.py

示例14: fill_calendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import monthcalendar [as 别名]
def fill_calendar(self):

        init_x = 40
        y = 70

        step_x = 27
        step_y = 20

        self.canvas.delete(self.base_number_tag)
        self.canvas.update()

        if self.selected_date is None:
            month_calender = calendar.monthcalendar(self.empty_date.year, self.empty_date.month)   
        else:
            month_calender = calendar.monthcalendar(self.selected_date.year, self.selected_date.month)   

        for row in month_calender:
            
            x = init_x 

            for item in row:    
            
                if item > 0:

                    self.canvas.create_text(x,
                                            y,
                                            text=str(item), 
                                            font=Calendar.FONT,
                                            tags=(self.base_number_tag, item))   

                    if not self.selected_date is None:
                        if self.selected_date.day == item:
                            self.move_to(self.circle_selected, (x, y))
                            self.show(self.circle_selected)

                x+= step_x
            
            y += step_y

        self.canvas.tag_bind(self.base_number_tag, "<ButtonRelease-1>", self.click_number)
        self.canvas.tag_bind(self.base_number_tag, "<Enter>", self.on_mouse_over)
        self.canvas.tag_bind(self.base_number_tag, "<Leave>", self.on_mouse_out) 
开发者ID:PCWG,项目名称:PCWG,代码行数:44,代码来源:date_pick.py


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