Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 22x 22x 22x 22x 22x 22x 22x | import { differenceInCalendarDays } from "date-fns";
export function getDaysDifferenceFromNow(timestamp: number | null) {
Iif (timestamp === null) return 0;
const now = new Date();
const endsAtDate = new Date(timestamp * 1000);
const endsAtUTC = new Date(
Date.UTC(
endsAtDate.getUTCFullYear(),
endsAtDate.getUTCMonth(),
endsAtDate.getUTCDate(),
),
);
const todayUTC = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()),
);
const diff = differenceInCalendarDays(todayUTC, endsAtUTC);
return diff;
}
export function getHoursFromTimestamp(timestamp: number | null) {
if (timestamp === null) return 0;
const date = new Date(timestamp * 1000);
return date.getHours();
}
|