25 lines
774 B
TypeScript
25 lines
774 B
TypeScript
import dayjs from "dayjs";
|
|||
|
|
import duration from "dayjs/plugin/duration";
|
||
|
|
import utc from "dayjs/plugin/utc";
|
||
|
|
import timezone from "dayjs/plugin/timezone";
|
||
|
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
||
|
|
|
||
|
|
dayjs.extend(utc);
|
||
|
|
dayjs.extend(timezone);
|
||
|
|
dayjs.extend(customParseFormat);
|
||
|
|
dayjs.extend(duration);
|
||
|
|
|
||
|
|
export const MS_PER_SECOND = 1000;
|
||
|
|
export const MS_PER_MINUTE = 60 * MS_PER_SECOND;
|
||
|
|
export const MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
||
|
|
export const MS_PER_DAY = 24 * MS_PER_HOUR;
|
||
|
|
export const MS_PER_WEEK = MS_PER_DAY * 7;
|
||
|
|
|
||
|
|
export const formatDateWithTz = (timestamp: string, format: string, timezone: string) => {
|
||
|
|
if (!timestamp) {
|
||
|
|
return "Unknown time";
|
||
|
|
}
|
||
|
|
|
||
|
|
const formattedDate = dayjs(timestamp).tz(timezone).format(format);
|
||
|
|
return formattedDate;
|
||
|
|
};
|