Skip to content

Fix ChronosDate ordinal relative modifiers - #533

Open
dereuromark wants to merge 1 commit into
3.xfrom
fix/chronos-date-second-ordinal
Open

dereuromark wants to merge 1 commit into
3.xfrom
fix/chronos-date-second-ordinal

Conversation

@dereuromark

Copy link
Copy Markdown
Member

Summary

  • parse relative modifiers before rejecting time components, so ordinal expressions such as second monday of this month remain valid
  • reject uppercase, abbreviated, fractional, and wrapped-day time modifiers
  • reject negative time components passed to add() and sub()
  • preserve timestamp modifiers and date arithmetic across time zones that skip midnight

Tests

  • composer test
  • composer cs-check
  • composer stan (fails on the existing unmatched DateTimeImmutable::createFromTimestamp() ignore under PHP 8.5)

Closes #532

@dereuromark
dereuromark marked this pull request as ready for review September 16, 2026 12:48
@markstory markstory added this to the 3.x milestone Sep 19, 2026
Comment thread src/ChronosDate.php
$parsed = date_parse($modifier);
$relative = $parsed['relative'] ?? [];
$timestampSeconds = 0;
if (preg_match('/(?:^|\s)@(-?\d+)(?:\.\d+)?(?:\s|$)/', $modifier, $matches)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be simpler to check native after the modify() call and see if the new value has seconds/milliseconds/microseconds set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChronosDate::modify() fails on 'second' relative keywords

2 participants