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

parseDuration prohibits carry over values #5416

Open
mfwgenerics opened this issue Nov 14, 2023 · 2 comments
Open

parseDuration prohibits carry over values #5416

mfwgenerics opened this issue Nov 14, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@mfwgenerics
Copy link

Provide a general summary of the issue here

Valid ISO 8601 durations such as PT36H can not be parsed using parseDuration from @internationalized/date because 36 falls outside of the internal range constraint.

🤔 Expected Behavior?

parseDuration("PT36H")
{
   "years": 0,
   "months": 0,
   "weeks": 0,
   "days": 0,
   "hours": 36,
   "minutes": 0,
   "seconds": 0
}

😯 Current Behavior

parseDuration("PT36H")
Error: Invalid ISO 8601 Duration string: PT36H

💁 Possible Solution

These limits could be removed:

hours: parseDurationGroup(match.groups?.hours, isNegative, 0, 23),

🔦 Context

This current behavior makes it difficult to use parseDuration when you are working with time units only.

I can't tell exactly how the standard treats the issue, but it does seem that there is no general conversion between units. This makes sense to me, because P1DT12H could represent a longer, shorter or equivalent length of time to PT36H depending on the start date time (due to daylight savings). I believe most other ISO 8601 duration implementations preserve the distinction between P1DT12H and PT36H.

🖥️ Steps to Reproduce

import React from "react";
import { Provider, defaultTheme, Button } from "@adobe/react-spectrum";
import "./styles.css";
import { parseDuration } from "@internationalized/date";

export default function App() {
  return (
    <Provider theme={defaultTheme} height="100%">
      <Button variant={"primary"} onClick={() => {
        parseDuration("PT36H")
      }}>Click Me</Button>
    </Provider>
  );
}

Version

3.32.0

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

Linux

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@ktabors ktabors added the good first issue Good for newcomers label May 16, 2024
@ktabors
Copy link
Member

ktabors commented May 16, 2024

Thanks for the identifying this issue. parseDuration() from @internationalized/date should match the behavior of Temporal.Duration.

@mfwgenerics
Copy link
Author

Thanks @ktabors

For the benefit of future readers of this issue, here's the behavior of Temporal.Duration using the polyfill currently hosted on the reference docs.

const duration = Temporal.Duration.from("PT36H")
duration.hours
> 36
duration.days
> 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants