Git Product home page Git Product logo

Comments (4)

ptomato avatar ptomato commented on July 27, 2024

This is a regression from #2884. So while the bad news is that we may have inadvertently introduced a bug, the good news is that there wasn't TC39 consensus on the buggy behaviour, so we can just make it work again without having to go to plenary.

I'll investigate whether the best fix is a revert or something else, because there is definitely some stuff from #2884 that we should keep.

from proposal-temporal.

anba avatar anba commented on July 27, 2024
Temporal.PlainDate.from("2023-05-31").until("2024-04-30", {largestUnit: "month"}).toString()

returns "P10M30D", but used to return "P11M" at some point. SpiderMonkey still uses the old definition of DifferenceISODate, which is probably why it doesn't throw a RangeError for the round call.


Temporal.Duration.prototype.round calls DifferencePlainDateTimeWithRounding with one = 2023-05-31 and two = 2024-04-30. DifferenceISODateTime(one, two, largestUnit = "months") returns P10M30D. So RoundRelativeDuration is called with duration = P10M30D and increment = 1. In NudgeToCalendarUnit, r1 = 10 (months from P10M30D) and r2 = 11. Adding r2 months to the start date ("2023-05-31") returns the end date ("2024-04-30"), which leads to evaluating true for destEpochNs ≥ endEpochNs in NudgeToCalendarUnit, step 13.a.

If DifferenceISODateTime had returned "P11M" instead of "P10M30D", then r1 = 11 and r2 = 12, and everything would have worked correctly.

from proposal-temporal.

arshaw avatar arshaw commented on July 27, 2024

We probably just need to relax the assertions. See #2924

from proposal-temporal.

anba avatar anba commented on July 27, 2024

No, we can't just relax these range checks, because they ensure that ApplyUnsignedRoundingMode can be called without hitting assertions within ApplyUnsignedRoundingMode, specifically the Assert: r1 < x < r2. step.

Edit: I didn't see that you also propose to change ApplyUnsignedRoundingMode. I don't have enough time to check if ApplyUnsignedRoundingMode can be changed to allow r1 ≤ x ≤ r2 instead of the current requirement r1 ≤ x < r2.

That still leaves the question unanswered if Temporal.PlainDate.from("2023-05-31").until("2024-04-30", {largestUnit: "month"}).toString() should return "P10M30D" or "P11M". I'd prefer if this question is first answered before applying #2924.

from proposal-temporal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.