Skip to content

Fix GH-21027: strtotime() incorrectly parses decimal relative values#21034

Closed
khaledalam wants to merge 5 commits intophp:masterfrom
khaledalam:fix/gh-21027-strtotime-decimal-relative
Closed

Fix GH-21027: strtotime() incorrectly parses decimal relative values#21034
khaledalam wants to merge 5 commits intophp:masterfrom
khaledalam:fix/gh-21027-strtotime-decimal-relative

Conversation

@khaledalam
Copy link
Copy Markdown
Contributor

Description

Fixes #21027

strtotime("2.37685 weeks") returned incorrect result (~414 million seconds instead of ~1.4 million) because:

  • "2.37" matched timeshort24 pattern (hour:minute with dot separator)
  • "685 weeks" was parsed as separate relative offset

Changes

  • Added relnumberdec regex pattern for decimal numbers
  • Added relativedec lexer rule to match decimal relative expressions
  • Added timelib_get_decimal_nr() helper to parse decimal values
  • Added timelib_set_relative_decimal() to convert decimal units to seconds

@khaledalam khaledalam force-pushed the fix/gh-21027-strtotime-decimal-relative branch from e5cd267 to 03831de Compare January 25, 2026 12:41
@devnexen
Copy link
Copy Markdown
Member

You need to open a PR in the original repository instead.

@khaledalam
Copy link
Copy Markdown
Contributor Author

opened on original repo.

Close

@khaledalam khaledalam closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strtotime() has strange interpretation of decimal weeks

3 participants