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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 283x 46x 2x 44x 44x 44x 29x 29x 283x 2381x 2381x 191x 191x 2190x 283x 130x 130x 12x 10x 10x 10x 10x 10x | import { TZDate } from "@date-fns/tz";
import { UTCDate } from "@date-fns/utc";
import { add, format } from "date-fns";
import { differenceInDays } from "date-fns";
export const isDST = (date: Date): boolean => {
const jan = new Date(date).getTimezoneOffset();
const jul = new Date(new Date(date).setMonth(6)).getTimezoneOffset();
return new Date(date).getTimezoneOffset() < Math.max(jan, jul);
};
export function formatNinetyDaysDate(date: number | null | undefined): string {
if (!date) {
return "Pending";
}
const baseDate = new UTCDate(date);
const ninetyDaysLater = add(baseDate, { days: 90 });
return format(ninetyDaysLater, "MMM d, yyyy");
}
export function formatDate(dateValue: string | number) {
const dateObj = new Date(dateValue);
return format(dateObj, "MMMM d, yyyy");
}
export const formatDateToET = (
utcDateValue: string | number,
formatValue: string = "eee, MMM d yyyy, hh:mm:ss a",
includeTimezone: boolean = true,
) => {
const utcDateObj = new TZDate(new Date(utcDateValue).toISOString(), "America/New_York");
if (includeTimezone) {
const tzTag = format(utcDateObj, "z") === "GMT-5" ? "EST" : "EDT";
return format(utcDateObj, `${formatValue} '${tzTag}'`);
}
return format(utcDateObj, formatValue);
};
export const formatDateToUTC = (
utcDateValue: string | number,
formatValue: string = "MMMM d, yyyy",
) => {
const utcDateObj = new TZDate(new Date(utcDateValue).toISOString(), "UTC");
return format(utcDateObj, formatValue);
};
export function isWithinDays(dateValue?: number | string | null, days: number = 20): boolean {
if (!dateValue) return false;
const date = new Date(dateValue);
Iif (isNaN(date.getTime())) return false;
const now = new Date();
const diff = differenceInDays(now, date);
return diff >= 0 && diff <= days;
}
|