diff --git a/server/services/parsing/iso8601.ts b/server/services/parsing/iso8601.ts index 32fe3782e..de04a7bbb 100644 --- a/server/services/parsing/iso8601.ts +++ b/server/services/parsing/iso8601.ts @@ -3,12 +3,12 @@ * Examples: PT40M25S */ export function parseIso8601Duration(duration: string): number { - let match = /P(\d+D)?(?:T(\d+H)?(\d+M)?(\d+S)?)?/ + let match = /P(\d+D)?(?:T(\d+H)?(\d+M)?([\d.]+S)?)?/ .exec(duration) ?.slice(1) .map(x => { if (x !== null && x !== undefined) { - return x.replace(/\D/, ""); + return x.replace(/[^\d.]/, ""); } }); @@ -19,7 +19,7 @@ export function parseIso8601Duration(duration: string): number { const days = parseInt(match[0] ?? "0", 10) || 0; const hours = parseInt(match[1] ?? "0", 10) || 0; const minutes = parseInt(match[2] ?? "0", 10) || 0; - const seconds = parseInt(match[3] ?? "0", 10) || 0; + const seconds = parseFloat(match[3] ?? "0") || 0; return days * (24 * 3600) + hours * 3600 + minutes * 60 + seconds; } diff --git a/server/tests/unit/services/parsing/iso8601.spec.ts b/server/tests/unit/services/parsing/iso8601.spec.ts index f75518fc0..4aef01d35 100644 --- a/server/tests/unit/services/parsing/iso8601.spec.ts +++ b/server/tests/unit/services/parsing/iso8601.spec.ts @@ -3,6 +3,8 @@ import { parseIso8601Duration } from "../../../../services/parsing/iso8601"; describe("parse iso8601 duration", () => { it.each([ ["PT10S", 10], + ["PT10.0S", 10], + ["PT10.000S", 10], ["PT5M", 5 * 60], ["PT40M25S", 40 * 60 + 25], ["PT1H", 1 * 60 * 60],