Skip to content

fix: keep calendar date when subtracting years across historical TZ change - #3175

Open
arronKler wants to merge 1 commit into
iamkun:devfrom
arronKler:fix/3137-subtract-years-tz
Open

fix: keep calendar date when subtracting years across historical TZ change#3175
arronKler wants to merge 1 commit into
iamkun:devfrom
arronKler:fix/3137-subtract-years-tz

Conversation

@arronKler

Copy link
Copy Markdown

subtract(100, 'years') on 2081-12-25 in Asia/Kuala_Lumpur returned 1981-12-01 instead of 1981-12-25.

Year/month set clamps the day with daysInMonth(), which used endOf('month'). That builds local 23:59:59.999, and Malaysia’s 1981-12-31 midnight jump (UTC+7:30UTC+8) moves that instant onto 1982-01-01, so daysInMonth() becomes 1.

daysInMonth() now uses the UTC calendar month length, which is independent of that local last-millisecond construction.

Fixes #3137

…hange

daysInMonth() used endOf('month'), which builds local 23:59:59.999.
In Asia/Kuala_Lumpur that instant jumps across the 1981-12-31 UTC+7:30
to UTC+8 change, so the day becomes 1 and year/month set clamps to Dec 1.

Use the UTC calendar month length instead.

Fixes iamkun#3137
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.

subtract(years) causes incorrect date when crossing historical timezone change in Malaysia

1 participant