Quotation marks in Iso80000 range cause an exception
boris-glumpler opened this issue · comments
Bug Report
Information | Description |
---|---|
Version | 5.0 |
PHP version | 8.1 |
OS Platform | MacOS |
Summary
Well, it's not so much a bug maybe... In Postgres, a tsrange
or tstzrange
column will automatically wrap the dates in quotation marks, so you end up with something like ["2020-01-01 00:00:00+00","2020-01-21 00:00:00+00")
. When you then fetch that range from the database and plug it into Period::fromIso80000
you get an InvalidInterval
exception, because "2020-01-01 00:00:00+00"
is obviously not a valid date.
Currently, I just remove any "
in the range string before plugging it into Period::fromIso80000
, so it's not really a big issue, but could be nice if Period handles that internally. I'd be happy to create a PR if you like.
Standalone code, or other way to reproduce the problem
Period::fromIso80000('Y-m-d H:i:sP', '["2020-01-01 00:00:00+00","2020-01-21 00:00:00+00")');
Expected result
A valid Period
instance.
Actual result
League\Period\InvalidInterval: The date notation "2020-02-01 00:00:00+00"
is incompatible with the date format Y-m-d H:i:sP
.
@boris-glumpler thanks for using the library.
This is not a bug and no fix is even needed.
The format provided to Period::fromIso80000
should be supported by DateTimeImmutable::createFromFormat
. This means that Postgres format is already supported you just need follow the later requirements
To include literal characters in format, you have to escape them with a backslash ().
see https://www.php.net/manual/en/datetime.createfromformat.php
and a practical example https://3v4l.org/BsJep2
Yes, you're right. Didn't think of that ;) Cheers!