Files
js/utils/date-utils.ts
T
Tair Asim 64371d395b feat: embedded wallets (#1696)
* feat: embedded wallets

completes FTD-2165

* chore: smart wallets show factory deploy
2023-09-28 15:49:27 +00:00

26 lines
714 B
TypeScript

import { differenceInDays, format, isValid, parseISO } from "date-fns";
const DATE_TIME_LOCAL_FORMAT = "yyyy-MM-dd HH:mm";
export function toDateTimeLocal(date?: Date | number | string) {
if (typeof date === "number") {
date = new Date(date * 1000);
} else if (typeof date === "string") {
date = new Date(date);
}
return date && isValid(date)
? format(date, DATE_TIME_LOCAL_FORMAT)
: undefined;
}
export function toDateString(date: Date | string | number) {
return new Date(date).toISOString().split("T")[0];
}
export function withinDays(dateISO: string, days: number) {
const date = parseISO(dateISO);
const today = new Date();
return differenceInDays(today, date) <= days;
}