2024-02-24 21:23:30 +01:00
|
|
|
import { DateTime, Duration } from 'luxon';
|
2023-03-27 05:53:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert time like `01:02:03.456` to seconds.
|
|
|
|
|
*/
|
|
|
|
|
export function timeToSeconds(time: string) {
|
2023-07-01 00:50:47 -04:00
|
|
|
const parts = time.split(':');
|
|
|
|
|
parts[2] = parts[2].split('.').slice(0, 2).join('.');
|
2023-03-27 05:53:35 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const [hours, minutes, seconds] = parts.map(Number);
|
2023-03-27 05:53:35 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
return Duration.fromObject({ hours, minutes, seconds }).as('seconds');
|
2023-03-27 05:53:35 +02:00
|
|
|
}
|
2024-02-24 21:23:30 +01:00
|
|
|
|
|
|
|
|
export function parseUtcDate(date: string) {
|
|
|
|
|
return DateTime.fromISO(date, { zone: 'UTC' }).toUTC();
|
|
|
|
|
}
|