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


Python calendar.Calendar方法代码示例

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


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

示例1: test_localecalendars

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_localecalendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_calendar.py

示例2: test_locale_calendars

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_locale_calendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        self.assertIsInstance(local_weekday, str)
        self.assertIsInstance(local_month, str)
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        self.assertIsInstance(local_weekday, str)
        self.assertIsInstance(local_month, str)
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_calendar.py

示例3: addMonthsByFormatter

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def addMonthsByFormatter(self, months,dateFormat):
        d = datetime.datetime.now()
        c = calendar.Calendar()
        year = d.year
        month = d.month
        today = d.day
        if month+months > 12 :
            month = months
            year += 1
        else:
            month += months
        days = calendar.monthrange(year, month)[1]  
        
        if today > days:
            afteraddday = days
        else:
            afteraddday = today
        return datetime.datetime(year,month,afteraddday).strftime(dateFormat) 
开发者ID:gitjayzhen,项目名称:AppiumTestProject,代码行数:20,代码来源:DateTimeUtil.py

示例4: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def __init__(self, callback, year=None, month=None, day=None,
                 firstweekday=0,
                 **kwargs):
        self.callback = callback
        self.cal = calendar.Calendar(firstweekday)
        self.sel_year = year if year else self.today.year
        self.sel_month = month if month else self.today.month
        self.sel_day = day if day else self.today.day
        self.month = self.sel_month
        self.year = self.sel_year
        self.day = self.sel_day
        super(MDDatePicker, self).__init__(**kwargs)
        self.selector = DaySelector(parent=self)
        self.generate_cal_widgets()
        self.update_cal_matrix(self.sel_year, self.sel_month)
        self.set_month_day(self.sel_day)
        self.selector.update() 
开发者ID:kiok46,项目名称:Blogs-Posts-Tutorials,代码行数:19,代码来源:date_picker.py

示例5: formatyearpage

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def formatyearpage(self, theyear, width=3, css='calendar.css',
                       encoding=None):
        """
        Return a formatted year as a complete HTML page.
        """
        if encoding is None:
            encoding = sys.getdefaultencoding()
        v = []
        a = v.append
        a('<?xml version="1.0" encoding="%s"?>\n' % encoding)
        a('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n')
        a('<html>\n')
        a('<head>\n')
        a('<meta http-equiv="Content-Type" content="text/html; charset=%s" />\n' % encoding)
        if css is not None:
            a('<link rel="stylesheet" type="text/css" href="%s" />\n' % css)
        a('<title>Calendar for %d</title>\n' % theyear)
        a('</head>\n')
        a('<body>\n')
        a(self.formatyear(theyear, width))
        a('</body>\n')
        a('</html>\n')
        return ''.join(v).encode(encoding, "xmlcharrefreplace") 
开发者ID:PabloCastellano,项目名称:libreborme,代码行数:25,代码来源:calendar.py

示例6: test_config_unsafe_object_creation

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_config_unsafe_object_creation():
    from ruamel import yaml
    import calendar

    test_config_path = testing.relative_module_path(__file__, 'test_config_unsafe.yaml')

    # Unsafe default loader allows any python object initialization
    data = yaml.load(open(test_config_path), Loader=yaml.Loader)
    assert 'time' in data
    assert isinstance(data['time'], calendar.Calendar)

    # With use safe version only to allow construct previously registered objects
    with pytest.raises(config.ConfigLoadError, match='could not determine a constructor'):
        config.load_config(test_config_path) 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:16,代码来源:test_config.py

示例7: test_itermonthdates

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_itermonthdates(self):
        # ensure itermonthdates doesn't overflow after datetime.MAXYEAR
        # see #15421
        list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_calendar.py

示例8: test_itermonthdays

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_itermonthdays(self):
        for firstweekday in range(7):
            cal = calendar.Calendar(firstweekday)
            # Test the extremes, see #28253 and #26650
            for y, m in [(1, 1), (9999, 12)]:
                days = list(cal.itermonthdays(y, m))
                self.assertIn(len(days), (35, 42))
        # Test a short month
        cal = calendar.Calendar(firstweekday=3)
        days = list(cal.itermonthdays(2001, 2))
        self.assertEqual(days, list(range(1, 29))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_calendar.py

示例9: test_itermonthdays2

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_itermonthdays2(self):
        for firstweekday in range(7):
            cal = calendar.Calendar(firstweekday)
            # Test the extremes, see #28253 and #26650
            for y, m in [(1, 1), (9999, 12)]:
                days = list(cal.itermonthdays2(y, m))
                self.assertEqual(days[0][1], firstweekday)
                self.assertEqual(days[-1][1], (firstweekday - 1) % 7) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_calendar.py

示例10: test_option_type

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_option_type(self):
        self.assertFailure('-t')
        self.assertFailure('--type')
        self.assertFailure('-t', 'spam')
        stdout = self.run_ok('--type', 'text', '2004')
        self.assertEqual(stdout.strip(), conv(result_2004_text).strip())
        stdout = self.run_ok('--type', 'html', '2004')
        self.assertEqual(stdout[:6], b'<?xml ')
        self.assertIn(b'<title>Calendar for 2004</title>', stdout) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_calendar.py

示例11: month_days

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def month_days(year: int, month: int) -> Iterable[date]:
        return calendar.Calendar(calendar.firstweekday()).itermonthdates(year, month) 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:4,代码来源:gregorian_calendar.py

示例12: month_days_with_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def month_days_with_weekday(year: int, month: int) -> List[List[int]]:
        return calendar.Calendar(calendar.firstweekday()).monthdayscalendar(year, month) 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:4,代码来源:gregorian_calendar.py

示例13: test_yeardatescalendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_yeardatescalendar(self):
        def shrink(cal):
            return [[[' '.join('{:02d}/{:02d}/{}'.format(
                                d.month, d.day, str(d.year)[-2:]) for d in z)
                            for z in y] for y in x] for x in cal]
        self.assertEqual(
            shrink(calendar.Calendar().yeardatescalendar(2004)),
            result_2004_dates
        ) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_calendar.py

示例14: test_yeardayscalendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_yeardayscalendar(self):
        self.assertEqual(
            calendar.Calendar().yeardayscalendar(2004),
            result_2004_days
        ) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_calendar.py

示例15: test_option_type

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import Calendar [as 别名]
def test_option_type(self):
        self.assertFailure('-t')
        self.assertFailure('--type')
        self.assertFailure('-t', 'spam')
        stdout = self.run_ok('--type', 'text', '2004')
        self.assertEqual(stdout, conv(result_2004_text))
        stdout = self.run_ok('--type', 'html', '2004')
        self.assertEqual(stdout[:6], b'<?xml ')
        self.assertIn(b'<title>Calendar for 2004</title>', stdout) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_calendar.py


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