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

fix: remove hours limit for parseDuration #7064

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@internationalized/date/src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export function parseDuration(value: string): Required<DateTimeDuration> {
months: parseDurationGroup(match.groups?.months, isNegative, 0, 12),
weeks: parseDurationGroup(match.groups?.weeks, isNegative, 0, Infinity),
days: parseDurationGroup(match.groups?.days, isNegative, 0, 31),
hours: parseDurationGroup(match.groups?.hours, isNegative, 0, 23),
hours: parseDurationGroup(match.groups?.hours, isNegative, 0, Infinity),
minutes: parseDurationGroup(match.groups?.minutes, isNegative, 0, 59),
seconds: parseDurationGroup(match.groups?.seconds, isNegative, 0, 59)
};
Expand Down
29 changes: 26 additions & 3 deletions packages/@internationalized/date/tests/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,32 @@ describe('string conversion', function () {
});
});

it('parses an ISO 8601 duration string that contains years, months, hours, and seconds including hours exceeding 23 and returns a DateTimeDuration object', function () {
const duration = parseDuration('P18Y7MT30H15S');
expect(duration).toStrictEqual({
years: 18,
months: 7,
weeks: 0,
days: 0,
hours: 30,
minutes: 0,
seconds: 15
});
});

it('parses an ISO 8601 duration string that contains years, months, hours, and seconds including hours exceeding 23 and returns a DateTimeDuration object', function () {
const duration = parseDuration('PT36H');
expect(duration).toStrictEqual({
years: 0,
months: 0,
weeks: 0,
days: 0,
hours: 36,
minutes: 0,
seconds: 0
});
});

it('throws an error when passed an improperly formatted ISO 8601 duration string', function () {
expect(() => {
parseDuration('+-P18Y7MT20H15S');
Expand All @@ -550,9 +576,6 @@ describe('string conversion', function () {
expect(() => {
parseDuration('P18Y7MT');
}).toThrow('Invalid ISO 8601 Duration string: P18Y7MT');
expect(() => {
parseDuration('P18Y7MT30H15S');
}).toThrow('Invalid ISO 8601 Duration string: P18Y7MT30H15S');
expect(() => {
parseDuration('7Y6D85');
}).toThrow('Invalid ISO 8601 Duration string: 7Y6D85');
Expand Down