mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(web): handle edge cases in timeToSeconds function to prevent crashes (#21019)
Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com>
This commit is contained in:
parent
3bfa8b7575
commit
0729887c9c
2 changed files with 34 additions and 8 deletions
|
|
@ -7,14 +7,14 @@ import { get } from 'svelte/store';
|
|||
* Convert time like `01:02:03.456` to seconds.
|
||||
*/
|
||||
export function timeToSeconds(time: string) {
|
||||
const parts = time.split(':');
|
||||
parts[2] = parts[2].split('.').slice(0, 2).join('.');
|
||||
if (!time || time === '0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const [hours, minutes, seconds] = parts.map(Number);
|
||||
const seconds = Duration.fromISOTime(time).as('seconds');
|
||||
|
||||
return Duration.fromObject({ hours, minutes, seconds }).as('seconds');
|
||||
return Number.isNaN(seconds) ? 0 : seconds;
|
||||
}
|
||||
|
||||
export function parseUtcDate(date: string) {
|
||||
return DateTime.fromISO(date, { zone: 'UTC' }).toUTC();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue