feat(parser): add ISO8601 duration parser

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 15:02:08 +02:00
parent 5b714919a0
commit c56201c5f3
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { describe, it, expect } from 'vitest';
import { parseIso8601Duration } from '../../src/lib/server/parsers/iso8601-duration';
describe('parseIso8601Duration', () => {
it.each([
['PT30M', 30],
['PT1H', 60],
['PT1H30M', 90],
['PT2H15M', 135],
['PT0M', 0],
['P1DT2H', 26 * 60],
['PT90M', 90]
] as const)('parses %s to %i minutes', (input, expected) => {
expect(parseIso8601Duration(input)).toBe(expected);
});
it.each([[''], [null], [undefined], ['garbage'], ['30 min'], ['PT']])(
'returns null for invalid input %j',
(input) => {
expect(parseIso8601Duration(input as string)).toBeNull();
}
);
});