Skip to content

[codex] fix historical timezone endOf regression#3040

Open
susiwen8 wants to merge 2 commits intoiamkun:devfrom
susiwen8:codex/fix-issue-3003-days-in-month
Open

[codex] fix historical timezone endOf regression#3040
susiwen8 wants to merge 2 commits intoiamkun:devfrom
susiwen8:codex/fix-issue-3003-days-in-month

Conversation

@susiwen8
Copy link
Copy Markdown
Contributor

@susiwen8 susiwen8 commented Apr 8, 2026

Summary

  • fix endOf() boundary calculations to derive the last instant from the next unit boundary instead of constructing local 23:59:59.999
  • add a regression test for issue daysInMonth() returns 1 when timezone is Asia/Kuala_Lumpur #3003 covering the historical midnight offset shift in Asia/Singapore / Asia/Kuala_Lumpur
  • run the regression under TZ=Asia/Singapore in the test script so the bug stays covered in CI

Root Cause

daysInMonth() relies on endOf('month').date(). For 1981-12-01 in Singapore and Kuala Lumpur, constructing the local month end as 1981-12-31 23:59:59.999 crosses the midnight offset jump to UTC+08:00, so the native Date normalizes to 1982-01-01 00:29:59 and the day becomes 1.

This patch follows Moment's approach and computes endOf(...) as startOf(nextUnit) - 1ms, which preserves the correct local last day even when midnight itself has a historical offset change.

Validation

  • TZ=Asia/Singapore npm run test-issue3003
  • TZ=Asia/Kuala_Lumpur npx jest test/issues/issue3003.test.js --runInBand --coverage=false
  • npx jest test/display.test.js test/manipulate.test.js --runInBand --coverage=false
  • npx jest test/plugin/badMutable.test.js --runInBand --coverage=false
  • npx jest test/plugin/timezone.test.js --runInBand --coverage=false -t "startOf and endOf"
  • TZ=Asia/Singapore npm run test-tz
  • npx eslint src/index.js test/issues/issue3003.test.js
  • npm test runs with 94/94 suites and 776/776 tests passing, but currently exits non-zero because the repository's global coverage threshold still reports lines 99.95% < 100%

@susiwen8 susiwen8 marked this pull request as ready for review April 8, 2026 14:57
@susiwen8 susiwen8 marked this pull request as draft April 8, 2026 15:10
@susiwen8 susiwen8 closed this Apr 8, 2026
@susiwen8 susiwen8 reopened this Apr 8, 2026
@susiwen8 susiwen8 marked this pull request as ready for review April 8, 2026 15:25
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.

1 participant