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


Python Calendar.monthdays2calendar方法代码示例

本文整理汇总了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
开发者ID:mastodon667,项目名称:ISP,代码行数:58,代码来源:calendar_data.py

示例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
开发者ID:wikimedia,项目名称:mediawiki-tools-release,代码行数:13,代码来源:task-series.py

示例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,
    }
开发者ID:rob-b,项目名称:Jung,代码行数:14,代码来源:schedule_tags.py

示例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,
    }
开发者ID:Vlinking,项目名称:django-rest-calendar,代码行数:15,代码来源:views.py

示例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,
    }
开发者ID:Vlinking,项目名称:django-rest-calendar,代码行数:19,代码来源:views.py

示例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)
开发者ID:hozano,项目名称:pontox,代码行数:20,代码来源:models.py


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