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


Python calendar.day_name方法代码示例

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


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

示例1: convertToDay

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def convertToDay(toks):
    now = datetime.now()
    if "wkdayRef" in toks:
        todaynum = now.weekday()
        daynames = [n.lower() for n in calendar.day_name]
        nameddaynum = daynames.index(toks.wkdayRef.day.lower())
        if toks.wkdayRef.dir > 0:
            daydiff = (nameddaynum + 7 - todaynum) % 7
        else:
            daydiff = -((todaynum + 7 - nameddaynum) % 7)
        toks["absTime"] = datetime(now.year, now.month, now.day)+timedelta(daydiff)
    else:
        name = toks.name.lower()
        toks["absTime"] = {
            "now"       : now,
            "today"     : datetime(now.year, now.month, now.day),
            "yesterday" : datetime(now.year, now.month, now.day)+timedelta(-1),
            "tomorrow"  : datetime(now.year, now.month, now.day)+timedelta(+1),
            }[name] 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:21,代码来源:deltaTime.py

示例2: test_names

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def test_names(self, data, time_locale):
        # GH 17354
        # Test .weekday_name, .day_name(), .month_name
        with tm.assert_produces_warning(FutureWarning,
                                        check_stacklevel=False):
            assert data.weekday_name == 'Monday'
        if time_locale is None:
            expected_day = 'Monday'
            expected_month = 'August'
        else:
            with tm.set_locale(time_locale, locale.LC_TIME):
                expected_day = calendar.day_name[0].capitalize()
                expected_month = calendar.month_name[8].capitalize()

        assert data.day_name(time_locale) == expected_day
        assert data.month_name(time_locale) == expected_month

        # Test NaT
        nan_ts = Timestamp(NaT)
        assert np.isnan(nan_ts.day_name(time_locale))
        assert np.isnan(nan_ts.month_name(time_locale)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:test_timestamp.py

示例3: convert_abs_day_reference_to_date

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def convert_abs_day_reference_to_date(t):
    now = datetime.now().replace(microsecond=0)

    # handle day reference by weekday name
    if "day_name" in t:
        todaynum = now.weekday()
        daynames = [n.lower() for n in weekday_name_list]
        nameddaynum = daynames.index(t.day_name.lower())
        # compute difference in days - if current weekday name is referenced, then
        # computed 0 offset is changed to 7
        if t.dir > 0:
            daydiff = (nameddaynum + 7 - todaynum) % 7 or 7
        else:
            daydiff = -((todaynum + 7 - nameddaynum) % 7 or 7)
        t["abs_date"] = datetime(now.year, now.month, now.day) + timedelta(daydiff)
    else:
        name = t[0]
        t["abs_date"] = {
            "now": now,
            "today": datetime(now.year, now.month, now.day),
            "yesterday": datetime(now.year, now.month, now.day) + timedelta(days=-1),
            "tomorrow": datetime(now.year, now.month, now.day) + timedelta(days=+1),
        }[name] 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:25,代码来源:delta_time.py

示例4: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def __init__(self, config: Configuration, repository: GitRepository):
        self.path = None
        self.configuration = config
        self.assets_path = os.path.join(HERE, self.assets_subdir)
        self.git_repository_statistics = repository
        self.has_tags_page = config.do_process_tags()
        self._time_sampling_interval = "W"
        self._do_generate_index_page = False
        self._is_blame_data_allowed = False
        self._max_orphaned_extensions_count = 0

        templates_dir = os.path.join(HERE, self.templates_subdir)
        self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
        self.j2_env.filters['to_month_name_abr'] = lambda im: calendar.month_abbr[im]
        self.j2_env.filters['to_weekday_name'] = lambda i: calendar.day_name[i]
        self.j2_env.filters['to_ratio'] = lambda val, max_val: (float(val) / max_val) if max_val != 0 else 0
        self.j2_env.filters['to_percentage'] = lambda val, max_val: (100 * float(val) / max_val) if max_val != 0 else 0
        colors = colormaps.colormaps[self.configuration['colormap']]
        self.j2_env.filters['to_heatmap'] = lambda val, max_val: "%d, %d, %d" % colors[int(float(val) / max_val * (len(colors) - 1))] 
开发者ID:vifactor,项目名称:repostat,代码行数:21,代码来源:htmlreportcreator.py

示例5: number_to_day

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def number_to_day(self, day_number):
        """Returns localized day name by its CRON number

        Args:
            day_number: Number of a day
        Returns:
            Day corresponding to day_number
        Raises:
            IndexError: When day_number is not found
        """
        return [
            calendar.day_name[6],
            calendar.day_name[0],
            calendar.day_name[1],
            calendar.day_name[2],
            calendar.day_name[3],
            calendar.day_name[4],
            calendar.day_name[5]
        ][day_number] 
开发者ID:Salamek,项目名称:cron-descriptor,代码行数:21,代码来源:ExpressionDescriptor.py

示例6: GetSchedule

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def GetSchedule(self):
        """
        Get the cleaning schedule for this robot

        Returns:
            A dictionary representing the schedule per day (dict)
        """
        res = self._PostToRobot("get", "week")
        schedule = {}
        for idx in range(7):
            cal_day_idx = idx - 1
            if cal_day_idx < 0:
                cal_day_idx = 6
            schedule[calendar.day_name[cal_day_idx]] = {
                "clean" : True if res["cycle"][idx] == "start" else False,
                "startTime" : datetime.time(res["h"][idx], res["m"][idx])
            }
        return schedule 
开发者ID:cseelye,项目名称:pyirobot,代码行数:20,代码来源:__init__.py

示例7: test_dt_accessor_datetime_name_accessors

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def test_dt_accessor_datetime_name_accessors(self, time_locale):
        # Test Monday -> Sunday and January -> December, in that sequence
        if time_locale is None:
            # If the time_locale is None, day-name and month_name should
            # return the english attributes
            expected_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
                             'Friday', 'Saturday', 'Sunday']
            expected_months = ['January', 'February', 'March', 'April', 'May',
                               'June', 'July', 'August', 'September',
                               'October', 'November', 'December']
        else:
            with tm.set_locale(time_locale, locale.LC_TIME):
                expected_days = calendar.day_name[:]
                expected_months = calendar.month_name[1:]

        s = Series(DatetimeIndex(freq='D', start=datetime(1998, 1, 1),
                                 periods=365))
        english_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
                        'Friday', 'Saturday', 'Sunday']
        for day, name, eng_name in zip(range(4, 11),
                                       expected_days,
                                       english_days):
            name = name.capitalize()
            assert s.dt.weekday_name[day] == eng_name
            assert s.dt.day_name(locale=time_locale)[day] == name
        s = s.append(Series([pd.NaT]))
        assert np.isnan(s.dt.day_name(locale=time_locale).iloc[-1])

        s = Series(DatetimeIndex(freq='M', start='2012', end='2013'))
        result = s.dt.month_name(locale=time_locale)
        expected = Series([month.capitalize() for month in expected_months])
        tm.assert_series_equal(result, expected)
        for s_date, expected in zip(s, expected_months):
            result = s_date.month_name(locale=time_locale)
            assert result == expected.capitalize()
        s = s.append(Series([pd.NaT]))
        assert np.isnan(s.dt.month_name(locale=time_locale).iloc[-1]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:39,代码来源:test_datetime_values.py

示例8: test_name

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def test_name(self):
        for i, day_name in enumerate(calendar.day_abbr):
            self.assertEqual(WeekdaySetBuilder().build(day_name), {i})

        for i, day_name in enumerate(calendar.day_name):
            self.assertEqual(WeekdaySetBuilder().build(day_name), {i}) 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:8,代码来源:test_weekday_setbuilder.py

示例9: __calc_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def __calc_weekday(self):
        # Set self.a_weekday and self.f_weekday using the calendar
        # module.
        a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
        f_weekday = [calendar.day_name[i].lower() for i in range(7)]
        self.a_weekday = a_weekday
        self.f_weekday = f_weekday 
开发者ID:war-and-code,项目名称:jawfish,代码行数:9,代码来源:_strptime.py

示例10: test_names

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def test_names(self, data, time_locale):
        # GH 17354
        # Test .weekday_name, .day_name(), .month_name
        with tm.assert_produces_warning(FutureWarning,
                                        check_stacklevel=False):
            assert data.weekday_name == 'Monday'
        if time_locale is None:
            expected_day = 'Monday'
            expected_month = 'August'
        else:
            with tm.set_locale(time_locale, locale.LC_TIME):
                expected_day = calendar.day_name[0].capitalize()
                expected_month = calendar.month_name[8].capitalize()

        result_day = data.day_name(time_locale)
        result_month = data.month_name(time_locale)

        # Work around https://github.com/pandas-dev/pandas/issues/22342
        # different normalizations

        if not PY2:
            expected_day = unicodedata.normalize("NFD", expected_day)
            expected_month = unicodedata.normalize("NFD", expected_month)

            result_day = unicodedata.normalize("NFD", result_day,)
            result_month = unicodedata.normalize("NFD", result_month)

        assert result_day == expected_day
        assert result_month == expected_month

        # Test NaT
        nan_ts = Timestamp(NaT)
        assert np.isnan(nan_ts.day_name(time_locale))
        assert np.isnan(nan_ts.month_name(time_locale)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:36,代码来源:test_timestamp.py

示例11: filter_day_time

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def filter_day_time(self, candidates, criterion, now=None):
        """ Passed unchanged list of candidates, if the execution time
            satisfies the policy requirements.
        """
        now = now or datetime.now()
        self.logger.debug("Now is %r", now)

        # check the day is permitted
        day_name = calendar.day_name[now.weekday()].lower()
        permitted_days = criterion.get("onlyDays", [])
        if permitted_days and day_name not in permitted_days:
            self.logger.info("Not allowed on %s", day_name)
            return []

        # check the time is not too early
        start = criterion.get("startTime", {})
        start_date = now.replace(
            hour=start.get("hour", 10),
            minute=start.get("minute", 0),
            second=start.get("second", 0),
        )
        if now < start_date:
            self.logger.info("Too early")
            return []

        # check the time is not too late
        end = criterion.get("endTime", {})
        end_date = now.replace(
            hour=end.get("hour", 15),
            minute=end.get("minute", 59),
            second=end.get("second", 59),
        )
        if now > end_date:
            self.logger.info("Too late")
            return []

        return candidates 
开发者ID:bloomberg,项目名称:powerfulseal,代码行数:39,代码来源:action_nodes_pods.py

示例12: get_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def get_weekday(day_delta):
        now = dt.datetime.now()
        if day_delta == 'd_2':
            day_time = now - dt.timedelta(days=2)
        elif day_delta == 'd_1':
            day_time = now - dt.timedelta(days=1)
        elif day_delta == 'd1':
            day_time = now + dt.timedelta(days=1)
        elif day_delta == 'd2':
            day_time = now + dt.timedelta(days=2)
        else:
            day_time = now

        weekday = cal.day_name[day_time.weekday()]
        return "{}, {:%B %d, %Y}".format(weekday, day_time) 
开发者ID:bshao001,项目名称:ChatLearner,代码行数:17,代码来源:functiondata.py

示例13: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [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

示例14: forecast

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def forecast(idx):
    date = datetime.fromtimestamp(int(data['daily']['data'][idx]['time']))
    day = calendar.day_name[date.weekday()]
    lo = data['daily']['data'][idx]['temperatureMin']
    hi = data['daily']['data'][idx]['temperatureMax']
    cond = data['daily']['data'][idx]['summary']
    print(date)
    print(day)
    print(lo)
    print(hi)
    print(cond)
    time.sleep(1)
    printer.set(
        font='a',
        height=2,
        align='left',
        bold=False,
        double_height=False)
    printer.text(day + ' \n ')
    time.sleep(5)           # Sleep to prevent printer buffer overflow
    printer.text('\n')
    printer.image(forecast_icon(idx))
    printer.text('low ' + str(lo))
    printer.text(deg)
    printer.text('\n')
    printer.text(' high ' + str(hi))
    printer.text(deg)
    printer.text('\n')
    # take care of pesky unicode dash
    printer.text(cond.replace(u'\u2013', '-').encode('utf-8'))
    printer.text('\n \n') 
开发者ID:python-escpos,项目名称:python-escpos,代码行数:33,代码来源:weather.py

示例15: dayOfTheWeek

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import day_name [as 别名]
def dayOfTheWeek(self, day: int, month: int, year: int) -> str:
        import datetime, calendar
        return calendar.day_name[datetime.date(year, month, day).weekday()] 
开发者ID:YaxeZhang,项目名称:Just-Code,代码行数:5,代码来源:day-of-the-week.py


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