brick / date-time

Date and time library for PHP
MIT License
337 stars 30 forks source link

`LocalDate::parse(...)` does not recognise ISO-8601 #93

Closed joelbutcher closed 8 months ago

joelbutcher commented 8 months ago

Trying to parse the following:

\Brick\DateTime\LocalDate::parse('2024-03-11T00:00:00.000Z');

results in:

Brick\DateTime\Parser\DateTimeParseException  Failed to parse "2024-03-11T00:00:00.000Z"
BenMorel commented 8 months ago

Hi, your string is the ISO 8601 representation of a date-time with a timezone, which is represented in brick/date-time by ZonedDateTime:

\Brick\DateTime\ZonedDateTime::parse('2024-03-11T00:00:00.000Z'); // works

If you need only the date part (a LocalDate), you can call ZonedDateTime::getDate():

\Brick\DateTime\ZonedDateTime::parse('2024-03-11T00:00:00.000Z')->getDate();

Or pass just the date part to LocalDate::parse():

\Brick\DateTime\LocalDate::parse('2024-03-11'); // works