2024-07-29 20:11:13 +00:00
|
|
|
import dayjs, { Dayjs } from "dayjs";
|
|
|
|
|
2024-07-03 17:17:47 +00:00
|
|
|
/**
|
|
|
|
* Get current UNIX time, in seconds
|
|
|
|
*/
|
|
|
|
export function time(): number {
|
|
|
|
return Math.floor(new Date().getTime() / 1000);
|
|
|
|
}
|
2024-07-29 20:11:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get dayjs representation of given time of day
|
|
|
|
*/
|
|
|
|
export function timeOfDay(time: number): Dayjs {
|
|
|
|
const hours = Math.floor(time / 3600);
|
|
|
|
const minutes = Math.floor(time / 60) - hours * 60;
|
|
|
|
|
|
|
|
return dayjs(
|
|
|
|
`2022-04-17T${hours.toString().padStart(2, "0")}:${minutes
|
|
|
|
.toString()
|
|
|
|
.padStart(2, "0")}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get time of day (in secs) from a given dayjs representation
|
|
|
|
*/
|
|
|
|
export function dayjsToTimeOfDay(d: Dayjs): number {
|
|
|
|
return d.hour() * 3600 + d.minute() * 60 + d.second();
|
|
|
|
}
|