Skip to content

xs:duration does not support weeks #678

@aheissenberger

Description

@aheissenberger

The ISO 8601 standard allows to use Weeks but not combining them with other units.
The current implementation of the new browser Date API Temporal allows weeks to be combined with other units.

Example Duration P1W

DayTimeDuration.fromString = (dayTimeDurationString: string): DayTimeDuration | null => {
const regex = /^(-)?P(\d+Y)?(\d+M)?(\d+D)?(?:T(\d+H)?(\d+M)?(\d+(\.\d*)?S)?)?$/;
const match = regex.exec(dayTimeDurationString);
if (!match) {
return null;
}
const isPositive = !match[1];
const days = match[4] ? parseInt(match[4], 10) : 0;
const hours = match[5] ? parseInt(match[5], 10) : 0;
const minutes = match[6] ? parseInt(match[6], 10) : 0;
const seconds = match[7] ? parseInt(match[7], 10) : 0;
const secondFraction = match[8] ? parseFloat(match[8]) : 0;
return DayTimeDuration.fromParts(days, hours, minutes, seconds, secondFraction, isPositive);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions