2022-09-06 19:09:25 +02:00
|
|
|
/**
|
|
|
|
* Utility functions for "wibbly wobbly timey wimey" stuff.
|
|
|
|
*/
|
2022-09-14 16:33:43 +02:00
|
|
|
import type { UnixTimestampMilliseconds, UnixTimestampSeconds } from "../types";
|
2022-09-06 19:09:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an {@link UnixTimestampMilliseconds} to an {@link UnixTimestampSeconds} rounding down.
|
|
|
|
*
|
|
|
|
* @param ms - The timestamp in milliseconds.
|
|
|
|
* @returns - The timestamp in seconds.
|
|
|
|
*/
|
|
|
|
export function toUnixTimestampSeconds(
|
|
|
|
ms: UnixTimestampMilliseconds
|
|
|
|
): UnixTimestampSeconds {
|
|
|
|
return Math.floor(ms / 1000) as UnixTimestampSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an {@link UnixTimestampSeconds} to an {@link UnixTimestampMilliseconds}.
|
|
|
|
*
|
|
|
|
* @param s - The timestamp in seconds.
|
|
|
|
* @returns - The timestamp in milliseconds.
|
|
|
|
*/
|
|
|
|
export function toUnixTimestampMilliseconds(
|
|
|
|
s: UnixTimestampSeconds
|
|
|
|
): UnixTimestampMilliseconds {
|
|
|
|
return (s * 1000) as UnixTimestampMilliseconds;
|
|
|
|
}
|