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

ZonedDateTime.from() / .with() overflow option default #2909

Closed
chrisveness opened this issue Jul 3, 2024 · 1 comment
Closed

ZonedDateTime.from() / .with() overflow option default #2909

chrisveness opened this issue Jul 3, 2024 · 1 comment

Comments

@chrisveness
Copy link

In ZonedDateTime.from(), the overflow option apparently defaults to constrain (rather than reject).

The effect of this is to silently update parameters without warning. This seems unfriendly behaviour, and a likely foot-gun.

I encountered this in the following context:

const t1 = Temporal.Instant.from('2024-03-31T23:45Z').toZonedDateTimeISO('UTC');
const t2 = t1.with({ hour: 24, minute: 0, second: 0 });
console.log(t2.toString());

I was anticipating a resulting time of midnight (or otherwise an error), and was very surprised to find it was 2024-03-31T23:00:00+00:00[UTC].

I would prefer to be warned of this, and explicitly set overflow to constrain if I actually wanted such behaviour.

@ptomato
Copy link
Collaborator

ptomato commented Jul 11, 2024

Thanks for the feedback! We discussed this in the 2024-07-11 meeting. Yes, this is unfortunately a case where there's not one right answer, so we're going to stick with the default that we have. In one context this is unfriendly, in another it's useful: e.g. #2840 (comment)

@ptomato ptomato closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants