pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

`parse_dt` method that specifically returns a DateTime

Open kerrickstaley opened this issue 3 months ago • 1 comments

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Feature Request

pdl.parse can return a Date, Time, Duration, or DateTime, depending on the args you pass to it. This is annoying in type-checked codebases, because you have to write

my_dt = pdl.parse(my_dt_string)
assert isinstance(my_dt, pdl.DateTime)

every time you want to parse a datetime string.

I wish there were a function parse_dt that was guaranteed to return a DateTime, and raises if you pass it something else like '2024-09-12T10:00:00Z/2024-09-12T15:30:00Z'.

kerrickstaley avatar Sep 12 '25 04:09 kerrickstaley

Sounds interesting. Maybe you want to make a PR implementing those 4 variants for the types you mentioned? We could discuss it further then.

Secrus avatar Sep 12 '25 16:09 Secrus