How to use the pendulum.parsing.parse function in pendulum

To help you get started, we’ve selected a few pendulum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdispater / pendulum / tests / parsing / test_parsing_duration.py View on Github external
assert parsed.microseconds == 0

    text = "P1Y2M3,5D"
    parsed = parse(text)

    assert parsed.years == 1
    assert parsed.months == 2
    assert parsed.weeks == 0
    assert parsed.remaining_days == 3
    assert parsed.hours == 12
    assert parsed.minutes == 0
    assert parsed.remaining_seconds == 0
    assert parsed.microseconds == 0

    text = "PT4H54M6.5S"
    parsed = parse(text)

    assert parsed.years == 0
    assert parsed.months == 0
    assert parsed.weeks == 0
    assert parsed.remaining_days == 0
    assert parsed.hours == 4
    assert parsed.minutes == 54
    assert parsed.remaining_seconds == 6
    assert parsed.microseconds == 500000

    text = "PT4H54M6,5S"
    parsed = parse(text)

    assert parsed.years == 0
    assert parsed.months == 0
    assert parsed.weeks == 0
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
def test_strict():
    text = "4 Aug 2015 - 11:20 PM"

    with pytest.raises(ParserError):
        parse(text)

    parsed = parse(text, strict=False)
    assert 2015 == parsed.year
    assert 8 == parsed.month
    assert 4 == parsed.day
    assert 23 == parsed.hour
    assert 20 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert parsed.tzinfo is None
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
def test_rfc_3339():
    text = "2016-10-06T12:34:56+05:30"

    parsed = parse(text)

    assert 2016 == parsed.year
    assert 10 == parsed.month
    assert 6 == parsed.day
    assert 12 == parsed.hour
    assert 34 == parsed.minute
    assert 56 == parsed.second
    assert 0 == parsed.microsecond
    assert 19800 == parsed.utcoffset().total_seconds()
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
def test_y():
    text = "2016"

    parsed = parse(text)

    assert 2016 == parsed.year
    assert 1 == parsed.month
    assert 1 == parsed.day
    assert 0 == parsed.hour
    assert 0 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert parsed.tzinfo is None
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
text = "20161001T1430"

    parsed = parse(text)

    assert 2016 == parsed.year
    assert 10 == parsed.month
    assert 1 == parsed.day
    assert 14 == parsed.hour
    assert 30 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert parsed.tzinfo is None

    text = "20161001T1430+0530"

    parsed = parse(text)

    assert 2016 == parsed.year
    assert 10 == parsed.month
    assert 1 == parsed.day
    assert 14 == parsed.hour
    assert 30 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert 19800 == parsed.utcoffset().total_seconds()

    text = "20161001T1430,4+0530"

    parsed = parse(text)

    assert 2016 == parsed.year
    assert 10 == parsed.month
github sdispater / pendulum / tests / parsing / test_parsing_duration.py View on Github external
def test_parse_duration_invalid_order():
    with pytest.raises(ParserError):
        parse("P1S")

    with pytest.raises(ParserError):
        parse("P1D1S")

    with pytest.raises(ParserError):
        parse("1Y2M3D1SPT1M")

    with pytest.raises(ParserError):
        parse("P1Y2M3D2MT1S")

    with pytest.raises(ParserError):
        parse("P2M3D1ST1Y1M")

    with pytest.raises(ParserError):
        parse("P1Y2M2MT3D1S")

    with pytest.raises(ParserError):
        parse("P1D1Y1M")

    with pytest.raises(ParserError):
        parse("PT1S1H")
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
def test_ymd_one_character():
    text = "2016-2-6"

    parsed = parse(text, strict=False)

    assert 2016 == parsed.year
    assert 2 == parsed.month
    assert 6 == parsed.day
    assert 0 == parsed.hour
    assert 0 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert parsed.tzinfo is None
github sdispater / pendulum / tests / parsing / test_parsing_duration.py View on Github external
def test_parse_duration_weeks_combined():
    with pytest.raises(ParserError):
        parse("P1Y2W")
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
def test_iso_8601_date():
    text = "2012"

    parsed = parse(text)

    assert 2012 == parsed.year
    assert 1 == parsed.month
    assert 1 == parsed.day
    assert 0 == parsed.hour
    assert 0 == parsed.minute
    assert 0 == parsed.second
    assert 0 == parsed.microsecond
    assert parsed.tzinfo is None

    text = "2012-05-03"

    parsed = parse(text)

    assert 2012 == parsed.year
    assert 5 == parsed.month
github sdispater / pendulum / tests / parsing / test_parsing.py View on Github external
assert 2012 == parsed.year
    assert 3 == parsed.month
    assert 13 == parsed.day

    text = "2012W055"

    parsed = parse(text, exact=True)

    assert isinstance(parsed, datetime.date)
    assert 2012 == parsed.year
    assert 2 == parsed.month
    assert 3 == parsed.day

    text = "2012007"

    parsed = parse(text, exact=True)

    assert isinstance(parsed, datetime.date)
    assert 2012 == parsed.year
    assert 1 == parsed.month
    assert 7 == parsed.day

    text = "20:12:05"

    parsed = parse(text, exact=True)

    assert isinstance(parsed, datetime.time)
    assert 20 == parsed.hour
    assert 12 == parsed.minute
    assert 5 == parsed.second
    assert 0 == parsed.microsecond