Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese calendar until throws "mixed-sign values not allowed as duration fields" RangeError #2537

Closed
justingrant opened this issue Mar 26, 2023 · 2 comments · Fixed by #2539
Labels
bug non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!

Comments

@justingrant
Copy link
Collaborator

justingrant commented Mar 26, 2023

Clearly this is a polyfill bug, but not sure if it reflects an underlying spec issue. Note that 2001 is a leap year in the chinese calendar that has an M04L leap month, so month 6 in 2001 is M05 while month 6 in 2000 is M06.

// 2001 is a leap year
Temporal.PlainDate.from({ year: 2001, month: 6, day: 1, calendar: 'chinese' })
  .since({ year: 2000, month: 6, day: 1, calendar: 'chinese' }, { largestUnit: 'year' })

It throws a RangeError:

ecmascript.mjs:3324 Uncaught RangeError: mixed-sign values not allowed as duration fields
    at Object.RejectDuration (ecmascript.mjs:3324:54)
    at new Duration (duration.mjs:47:8)
    at Calendar.dateUntil (calendar.mjs:165:12)
    at Object.Call (Call.js:19:9)
    at Object.CalendarDateUntil (ecmascript.mjs:1601:23)
    at Object.DifferenceTemporalPlainDate (ecmascript.mjs:3716:45)
    at Temporal.PlainDate.since (plaindate.mjs:136:15)
    at <anonymous>:2:4
@gibson042
Copy link
Collaborator

This is probably not a spec bug because non-ISO-8601 comparisons are implementation-defined, but if you can reproduce this with e.g. a leap day then a spec issue is more likely.

@justingrant
Copy link
Collaborator Author

if you can reproduce this with e.g. a leap day then a spec issue is more likely.

The problem turned out to be caused by a case that can never happen in the ISO calendar: when calculating the number of years between two dates where the years are different, the monthCodes are different, but the month is the same in both because the later date was after a leap month.

So not a spec issue (until non-ISO math is specified, of course!).

Fix available in #2539.

@ptomato ptomato closed this as completed in 2af503d Apr 4, 2023
justingrant added a commit that referenced this issue Apr 20, 2023
Fixes #2537.

UPSTREAM_COMMIT=2af503d36b7b0802d1f8e3166f1af38f9801c9e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants