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

Can't create 0-time Duration with constructor or .from() #189

Open
justinfagnani opened this issue Oct 13, 2022 · 1 comment
Open

Can't create 0-time Duration with constructor or .from() #189

justinfagnani opened this issue Oct 13, 2022 · 1 comment
Assignees

Comments

@justinfagnani
Copy link

I need to create a 0-time Duration for some testing purposes. I don't see anything in the Temporal proposal docs on Duration that seem to prevent this, but it doesn't seem possible in the current polyfill.

If I pass an empty object to .from() I get the error "invalid duration-like". If I pass no arguments to the constructor, or 0 or pass an a 0-valued property to .from(), like .from({minutes: 0}) I get the error "mixed-sign values not allowed as duration fields".

@justingrant
Copy link
Contributor

justingrant commented Oct 13, 2022

Hmm, could you provide a public repro case for this? I cannot repro the problem you're seeing. None of the code below (from this codesandbox) throws exceptions with version 0.4.2 of this polyfill.

import { Temporal } from "@js-temporal/polyfill";

Temporal.Duration.from("PT0S");
new Temporal.Duration(0);
Temporal.Duration.from({ minutes: 0 });
Temporal.Duration.from({ seconds: 0 });
Temporal.Duration.from({ minutes: -1, seconds: 0 });
Temporal.Duration.from({ minutes: 1, seconds: 0 });

The only time you should see the exception complaining about mixed signs would be if you try to do something like this:

Temporal.Duration.from({ minutes: -1, seconds: 1 });

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