當前位置: 首頁>>代碼示例>>Python>>正文


Python pendulum.from_format方法代碼示例

本文整理匯總了Python中pendulum.from_format方法的典型用法代碼示例。如果您正苦於以下問題:Python pendulum.from_format方法的具體用法?Python pendulum.from_format怎麽用?Python pendulum.from_format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pendulum的用法示例。


在下文中一共展示了pendulum.from_format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _parseDateInput

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def _parseDateInput(cls, date):
        """Verify that the given string is a valid date formatted as
        YYYY-MM-DD. Also, the API seems to go back until 2014-10-04,
        so we will check that the input is not a date earlier than that.
        In case of failure, throws a ValueError exception.
        """
        date = date.lower()

        if date in cls._FUZZY_DAYS:
            date = cls._EnglishDateToDate(date)

        elif date.replace("-", "").isdigit():
            try:
                parsed_date = pendulum.from_format(date, "YYYY-MM-DD")
            except:
                raise ValueError("Incorrect date format, should be YYYY-MM-DD")

            # The current API goes back until 2014-10-04. Is it in range?
            if parsed_date < pendulum.datetime(2014, 10, 4):
                raise ValueError("I can only go back until 2014-10-04")
        else:
            raise ValueError("Date is not valid")

        return cls._stripDateSeparators(date) 
開發者ID:oddluck,項目名稱:limnoria-plugins,代碼行數:26,代碼來源:plugin.py

示例2: test_from_format

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format(text, fmt, expected, now):
    if now is None:
        now = pendulum.datetime(2015, 11, 12)
    else:
        now = pendulum.parse(now)

    # Python 2.7 loses precision for x timestamps
    # so we don't test
    if fmt == "x" and PY2:
        return

    with pendulum.test(now):
        assert pendulum.from_format(text, fmt).isoformat() == expected 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:15,代碼來源:test_from_format.py

示例3: main

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def main(command, datetime=None):
    ctx = Context()
    if datetime is None:
        datetime = pendulum.now(ctx.config["TIMEZONE"])
    else:
        try:
            datetime = pendulum.from_format(datetime, 'YYYY-MM-DD', tz=ctx.config["TIMEZONE"])
            ctx.logger(f"Running in date override mode with date {datetime.format('YYYY-MM-DD')}.")
            ctx.logger("This is an experimental feature and may generate incorrect data.")
        except:
            ctx.logger("Failed to parse custom datetime argument")
            return 1
    try:
        outcome = ACTIONS[command](ctx, datetime)
    except Exception as exc:
        ctx.logger(exc)
        traceback.print_tb(exc.__traceback__)
        ctx.logger(f"{command} failed")
        return 1

    if outcome is 0:
        ctx.logger(f"{command} completed successfully")
        return 0
    else:
        ctx.logger(f"{command} failed")
        return 1 
開發者ID:metro-ontime,項目名稱:performance_tracker,代碼行數:28,代碼來源:main.py

示例4: extract_datetime

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def extract_datetime(path_to_dt, full_path, tz="UTC"):
    string_to_match = f"(?:{path_to_dt}/)([0-9]+-[0-9]+-[0-9]+)/([0-9]+:[0-9]+:[0-9]+)"
    dateinfo = re.match(string_to_match, full_path).groups()
    return pendulum.from_format(
        dateinfo[0] + "T" + dateinfo[1], "YYYY-MM-DDTHH:mm:ss", tz=tz
    ) 
開發者ID:metro-ontime,項目名稱:performance_tracker,代碼行數:8,代碼來源:datetimefs.py

示例5: extract_date

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def extract_date(path_to_dt, full_path, tz="UTC"):
    string_to_match = f"(?:{path_to_dt}/)([0-9]+-[0-9]+-[0-9]+)"
    dateinfo = re.match(string_to_match, full_path).groups()
    return pendulum.from_format(dateinfo[0], "YYYY-MM-DD", tz=tz) 
開發者ID:metro-ontime,項目名稱:performance_tracker,代碼行數:6,代碼來源:datetimefs.py

示例6: extract_time

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def extract_time(path_to_dt, full_path, tz="UTC"):
    string_to_match = f"(?:{path_to_dt}/)([0-9]+:[0-9]+:[0-9]+)"
    dateinfo = re.match(string_to_match, full_path).groups()
    return pendulum.from_format(dateinfo[0], "HH:mm:ss", tz=tz) 
開發者ID:metro-ontime,項目名稱:performance_tracker,代碼行數:6,代碼來源:datetimefs.py

示例7: services_running_on

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def services_running_on(self, datestring):
        within_range = self.on_date(datestring)
        date = pendulum.from_format(datestring, "YYYY-MM-DD")
        day = date.format("dddd").lower()
        services = within_range[within_range[day] == 1]
        if len(services.index) is 0:
            # This can apply on public holidays
            # The day flag can be incorrect so we
            # instead just look for services with a
            # start and end time exactly on the date
            services = self.exactly_on_date(datestring)
        return services 
開發者ID:metro-ontime,項目名稱:performance_tracker,代碼行數:14,代碼來源:calendar.py

示例8: test_from_format_returns_datetime

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_returns_datetime():
    d = pendulum.from_format("1975-05-21 22:32:11", "YYYY-MM-DD HH:mm:ss")
    assert_datetime(d, 1975, 5, 21, 22, 32, 11)
    assert isinstance(d, pendulum.DateTime)
    assert "UTC" == d.timezone_name 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:7,代碼來源:test_from_format.py

示例9: test_from_format_rejects_extra_text

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_rejects_extra_text():
    with pytest.raises(ValueError):
        pendulum.from_format("1975-05-21 22:32:11 extra text", "YYYY-MM-DD HH:mm:ss") 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:5,代碼來源:test_from_format.py

示例10: test_from_format_with_timezone_string

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_timezone_string():
    d = pendulum.from_format(
        "1975-05-21 22:32:11", "YYYY-MM-DD HH:mm:ss", tz="Europe/London"
    )
    assert_datetime(d, 1975, 5, 21, 22, 32, 11)
    assert "Europe/London" == d.timezone_name 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:8,代碼來源:test_from_format.py

示例11: test_from_format_with_timezone

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_timezone():
    d = pendulum.from_format(
        "1975-05-21 22:32:11",
        "YYYY-MM-DD HH:mm:ss",
        tz=pendulum.timezone("Europe/London"),
    )
    assert_datetime(d, 1975, 5, 21, 22, 32, 11)
    assert "Europe/London" == d.timezone_name 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:10,代碼來源:test_from_format.py

示例12: test_from_format_with_square_bracket_in_timezone

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_square_bracket_in_timezone():
    with pytest.raises(ValueError, match="^String does not match format"):
        pendulum.from_format(
            "1975-05-21 22:32:11 Eu[rope/London", "YYYY-MM-DD HH:mm:ss z",
        ) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:7,代碼來源:test_from_format.py

示例13: test_from_format_with_escaped_elements_valid_tokens

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_escaped_elements_valid_tokens():
    d = pendulum.from_format("1975-05-21T22:32:11.123Z", "YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")
    assert_datetime(d, 1975, 5, 21, 22, 32, 11)
    assert "UTC" == d.timezone_name 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:6,代碼來源:test_from_format.py

示例14: test_from_format_with_millis

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_millis():
    d = pendulum.from_format("1975-05-21 22:32:11.123456", "YYYY-MM-DD HH:mm:ss.SSSSSS")
    assert_datetime(d, 1975, 5, 21, 22, 32, 11, 123456) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:5,代碼來源:test_from_format.py

示例15: test_from_format_with_padded_day

# 需要導入模塊: import pendulum [as 別名]
# 或者: from pendulum import from_format [as 別名]
def test_from_format_with_padded_day():
    d = pendulum.from_format("Apr  2 12:00:00 2020 GMT", "MMM DD HH:mm:ss YYYY z")
    assert_datetime(d, 2020, 4, 2, 12) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:5,代碼來源:test_from_format.py


注:本文中的pendulum.from_format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。