-
Notifications
You must be signed in to change notification settings - Fork 155
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
Constructors should not accept invalid input #260
Comments
cc @ryzokuken , resident disambiguation expert. (Not knowing this area in detail, I might be OK with this being a bit stricter.) |
@gibson042 the constructors handle invalid input through disambiguation params while the |
That seems to throw away many benefits that Temporal should have, some of which I believe have been cited as explicit improvements over Date. Why is |
Meeting Jan. 27: Constructors should be strict, and we need to find another layer of the API to put the disambiguation. |
Moving the disambiguation from the constructor into from() raises one question that I hadn't anticipated: Temporal.Date.from({ year: 2019, month: 1, day: 32 }, { disambiguation: 'constrain' }) // => 2019-01-31
Temporal.Date.from('2019-01-32', { disambiguation: 'constrain' }) // throws Since this is an invalid ISO 8601 string to begin with, this should throw. This seems confusing to API users who would expect that the Temporal.Duration.from('PT100M', { disambiguation: 'balance' }) // => PT1H40M The difference is that |
This doesn't look terrible to me; it's just a reflection of the differences between strings (required to be valid per ISO 8601) and objects (inherently more flexible and in need of extra massaging). |
Fair enough. I pushed an extra commit to this branch making a note of this in the documentation, to clear up any potential confusion. |
We have decided that constructors are to be strict (what was previously achieved by passing 'reject' as the disambiguation parameter) and that the disambiguation should become part of the from() methods. Closes: #260.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
It was decided in #260 that overflow: 'constrain' should not affect invalid values coming from ISO strings, but it seems that it crept back in during a refactor. Fix this and add a test so that it doesn't regress again.
I find it surprising (in a negative sense) that Date, Time, DateTime, YearMonth, MonthDay, and Duration constructors have disambiguation parameters, allowing for e.g.
new Temporal.YearMonth(2019, 13)
to succeed whileTemporal.YearMonth.from("2019-13")
rightfully fails. This also seems to have spread to the with<Type> methods (withTime
,withDate
,withYear
, andwithDay
), which I thought were intended to losslessly preserve all data from the receiver and therefore have no use for disambiguation.The text was updated successfully, but these errors were encountered: