From 0106d9762ed4aee0767600193a0ba564d0fcddc9 Mon Sep 17 00:00:00 2001 From: Laura Whitaker Date: Fri, 27 Sep 2024 09:30:21 -0600 Subject: [PATCH] Fix differences in duration (#2353) * Use UTC dates for intervalToDuration in fromSeconds * Use UTC dates for intervalToDuration in fromSecondsToMinutesAndSeconds --- src/lib/utilities/format-time.ts | 6 ++++-- src/lib/utilities/to-duration.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/utilities/format-time.ts b/src/lib/utilities/format-time.ts index 40e907352..a29e924b8 100644 --- a/src/lib/utilities/format-time.ts +++ b/src/lib/utilities/format-time.ts @@ -193,9 +193,11 @@ export function getMilliseconds(date: ValidTime | undefined | null): number { export function fromSecondsToMinutesAndSeconds(seconds: number): string { if (!seconds) return ''; + const start = new Date(Date.UTC(0, 0, 0, 0, 0, 0)); + const end = new Date(Date.UTC(0, 0, 0, 0, 0, Math.floor(seconds))); const duration = intervalToDuration({ - start: 0, - end: Math.floor(seconds) * 1000, + start, + end, }); return durationToString(duration, { format: ['minutes', 'seconds'] }); } diff --git a/src/lib/utilities/to-duration.ts b/src/lib/utilities/to-duration.ts index b169f87f5..66fd38348 100644 --- a/src/lib/utilities/to-duration.ts +++ b/src/lib/utilities/to-duration.ts @@ -137,7 +137,9 @@ export const fromSeconds = ( if (!seconds.endsWith('s')) return ''; if (isNaN(parsedSeconds) || isNaN(parsedDecimal)) return ''; - const duration = intervalToDuration({ start: 0, end: parsedSeconds * 1000 }); + const start = new Date(Date.UTC(0, 0, 0, 0, 0, 0)); + const end = new Date(Date.UTC(0, 0, 0, 0, 0, parsedSeconds)); + const duration = intervalToDuration({ start, end }); const durationString = durationToString(duration, { delimiter }); const milliseconds = Math.round(parsedDecimal * 1000 * 1000000000) / 1000000000; // round to nanoseconds