Skip to content

Carry a time that rounds to midnight into the date exactly once - #107

Merged
borgar merged 1 commit into
borgar:masterfrom
arancool3000:fix/104-time-carry-midnight
Nov 2, 2026
Merged

borgar merged 1 commit into
borgar:masterfrom
arancool3000:fix/104-time-carry-midnight

Conversation

@arancool3000

Copy link
Copy Markdown
Contributor

What: yyyy-mm-dd didn't carry at 0.99999999999 (gave 1900-01-00), and yyyy-mm-dd hh:mm:ss carried twice at 45000.99999999999 (gave 2023-03-17 00:00:00). Excel gives 1900-01-01 / 1900-01-01 00:00:00 and 2023-03-16 / 2023-03-16 00:00:00.

Fix (src/runPart.ts):

  • A time that the existing sub-second epsilon correction pushes to 86400 s is now carried into the date for every date pattern, including date-only ones. A time that only reaches midnight by rounding to the shown unit still carries only when a time unit is shown, so the existing m/d/yy at 45292.99999999 → 1/1/24 behaviour is unchanged.
  • The serial passed to toYMD was value + date - trunc(value). Adding in floating point rounded 45001.99999999999 up to 45002, which caused the second carry. It is now floor(value) + date - trunc(value), an integer computed exactly.

Tests: added a case to test/numfmt.spec.ts with the four values from the issue. It fails before the fix and passes after. The full npm test suite, eslint and tsc are clean.

Fixes #104

AI-assisted (Claude); reviewed before submission.

Fixes borgar#104

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@borgar
borgar merged commit 036602e into borgar:master Nov 2, 2026
3 checks passed
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.

A time that rounds up to midnight moves the date by two days, or not at all

2 participants