當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。