You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateInterval month durations not accounting for calendar month days #18203
> now = Temporal.Now.zonedDateTimeISO()
> now.toString()
"2025-03-31T14:19:39.108140159+01:00[Europe/London]"
> now.add('P1M').toString()
"2025-04-30T14:19:39.108140159+01:00[Europe/London]"
Month durations / interval modifications should be able to account for calendar days per ISO 8601 and consistently change the month only without carrying excess days over and returning a date in the following month.
In the ISO8601 spec:
month
duration of 28, 29, 30 or 31 calendar days depending on the start and/or the end of the corresponding time
interval within the specific calendar month
NOTE 1 The term “month” applies also to the duration of any time interval which starts at a certain time of day at a
certain calendar day of the calendar month and ends at the same time of day at the same calendar day of the next
calendar month, if it exists. In other cases the ending calendar day has to be agreed on.
NOTE 2 In certain applications a month is considered as a duration of 30 calendar days.
Activity
heiglandreas commentedon Mar 31, 2025
Yes. This is a know problem of the logic you try to apply.
If you want to add one month to the 31st of January: Where do you end up?
31.01.2025 plus 1 month is 31.02.2025. Which then brings you to the problem that that day doesn't exist.
So how do you handle that?
Adding the overflowing days to the following month is the only sensible and logical way to handle this case.
If you want the last day of the following month (instead of adding one month) do something like
https://3v4l.org/YPUFa
derickr commentedon Apr 10, 2025
This is as expected, and also documented, so I'm closing this.