Skip to content

Commit

Permalink
Fix differences in duration (#2353)
Browse files Browse the repository at this point in the history
* Use UTC dates for intervalToDuration in fromSeconds

* Use UTC dates for intervalToDuration in fromSecondsToMinutesAndSeconds
  • Loading branch information
laurakwhit authored Sep 27, 2024
1 parent 4ac3e46 commit 0106d97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/lib/utilities/format-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] });
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/utilities/to-duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0106d97

Please sign in to comment.