Repository navigation
Fix ChronosDate ordinal relative modifiers - #533
dereuromark wants to merge 4 commits into
Conversation
| $parsed = date_parse($modifier); | ||
| $relative = $parsed['relative'] ?? []; | ||
| $timestampSeconds = 0; | ||
| if (preg_match('/(?:^|\s)@(-?\d+)(?:\.\d+)?(?:\s|$)/', $modifier, $matches)) { |
There was a problem hiding this comment.
Would it be simpler to check native after the modify() call and see if the new value has seconds/milliseconds/microseconds set?
There was a problem hiding this comment.
I tried that first, but it misses cases that land back on a clean time: +24 hours ends at midnight the next day and 1000 ms ends at 00:00:01.000000. It would also reject 12:00 and +1 day in zones that skip midnight (Havana 2023-03-12 gives 01:00). So the check stays before modify(). I added a comment saying why.
A post-modify time check cannot see '+24 hours' or '1000 ms', which land back on midnight or whole seconds, and would reject clock times and dates in time zones that skip midnight.
josbeir
left a comment
There was a problem hiding this comment.
All 993 tests pass, but there's a timestamp compatibility issue that the current tests don't cover.
josbeir
left a comment
There was a problem hiding this comment.
The timestamp whitespace cases are fixed, and all 999 tests pass on PHP 8.5.12. There's still one timestamp case that needs coverage.
date_parse() counts an @timestamp as relative seconds and negates them for 'ago', so '@86400 1 day ago' was rejected as a time adjustment. Removing the timestamp before parsing drops the bookkeeping that tried to cancel those seconds out.
Summary
second monday of this monthremain validadd()andsub()Closes #532