Skip to content

Error parsing timezones other than "Z" or "+00:00" #15

@sscherfke

Description

@sscherfke

I am not able to parse timezones other an Z/+00:00 with dtparse 1.3.2.

>>> dtparse.parse("2021-05-04 13:37:00+00:00", "%Y-%m-%d %H:%M:%S%:z")
datetime.datetime(2021, 5, 4, 13, 37)
>>> dtparse.parse("2021-05-04 13:37:00+10:00", "%Y-%m-%d %H:%M:%S%:z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no possible date and time matching input

>>> dtparse.parse("2021-05-04T13:37:00Z", "%+")
datetime.datetime(2021, 5, 4, 13, 37)
>>> dtparse.parse("2021-05-04T13:37:00+00:00", "%+")
datetime.datetime(2021, 5, 4, 13, 37)
>>> dtparse.parse("2021-05-04T13:37:00+01:00", "%+")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no possible date and time matching input

I'd also expect that tzinfo is attached to the datetime for Z/+00:00:

>>> dtparse.parse("2021-05-04 13:37:00+00:00", "%Y-%m-%d %H:%M:%S%:z")
datetime.datetime(2021, 5, 4, 13, 37, tzinfo=datetime.timezone.utc)
>>> dtparse.parse("2021-05-04T13:37:00Z", "%+")
datetime.datetime(2021, 5, 4, 13, 37, tzinfo=datetime.timezone.utc)
>>> dtparse.parse("2021-05-04T13:37:00+00:00", "%+")
datetime.datetime(2021, 5, 4, 13, 37, tzinfo=datetime.timezone.utc)

Did I miss something or is this a bug or even expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions