-
Notifications
You must be signed in to change notification settings - Fork 152
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
Why no Duration.prototype.compare
?
#608
Comments
It is intentional, because for some units in Temporal.Duration, you can't tell how long the duration actually is, without a start or end date. For example, which is longer: The way to compare durations would be to consider them relative to a start date: |
I don't think that solves the problem. const P2M = Temporal.Duration.from("P2M");
const P60D = Temporal.Duration.from("P60D");
function compareDurations(a, b, start) {
return Temporal.DateTime.compare(start.plus(a), start.plus(b))
}
compareDurations(P2M, P60D, Temporal.DateTime.from("2019-02-01T00:00")); // → -1
compareDurations(P2M, P60D, Temporal.DateTime.from("2019-07-01T00:00")); // → 1
compareDurations(P2M, P60D, Temporal.DateTime.from("2020-02-01T00:00")); // → 0 I'm also surprised by the absence of ¹ i.e., rejecting input with nonzero values on both sides of the months/days boundary, and rejecting or accepting input with nonzero values on both sides of the days/hours boundary consistently with the rest of Temporal |
I think this is an interesting proposal worth investigating. My main concern would be that exceptions might only show up at runtime, as opposed imposing limits in the types themselves (e.g. no BTW, after reviewing the entire Temporal API surface while building TypeScript types, the only type that feels like it has fundamental problems (i.e. not just naming or other minor issues) is Here's a summary:
I've been thinking over ways to address these problems in a holistic way, but haven't come up with any solutions yet. Probably a good thing to discuss in real time. Some questions to consider:
|
IIRC, the terms for these are, commonly:
That said, I'm more commonly familiar with .NET's |
Now that we've thoroughly revamped durations already, it might be time to tackle this one! What about:
My weakly-held preference is for 2; It seems like |
It's too soon for this, IMHO. I think the best sequencing will be to resolve the duration rounding decisions first (the discussion that we postponed from the 2020-07-31 marathon meeting after we couldn't resolve it after over an hour!), and then circle back to downstream questions like how should equals and compare be handled. It's possible that a parameter-less equals that requires strict equality (every unit must match, so |
Meeting 2020-09-11: We'll merge this into #856. Please continue discussion over there. Also, tentative conclusion (@pipobscure had the last word) was that we would not offer an |
Duration
doesn't have acompare
method. Is this intentional?The text was updated successfully, but these errors were encountered: