| [700e2f9] | 1 | export const formatDate = (dateString: string | Date) =>
|
|---|
| 2 | new Date(dateString).toLocaleDateString("en-US", {
|
|---|
| 3 | year: "numeric",
|
|---|
| 4 | month: "long",
|
|---|
| 5 | day: "numeric",
|
|---|
| 6 | });
|
|---|
| 7 |
|
|---|
| 8 | export const formatDateWithWeekday = (dateString: string | Date) =>
|
|---|
| 9 | new Date(dateString).toLocaleDateString("en-US", {
|
|---|
| 10 | weekday: "short",
|
|---|
| 11 | year: "numeric",
|
|---|
| 12 | month: "short",
|
|---|
| 13 | day: "numeric",
|
|---|
| 14 | });
|
|---|
| 15 |
|
|---|
| 16 | export const formatDateWithLongWeekday = (dateString: string | Date) =>
|
|---|
| 17 | new Date(dateString).toLocaleDateString("en-US", {
|
|---|
| 18 | weekday: "long",
|
|---|
| 19 | year: "numeric",
|
|---|
| 20 | month: "long",
|
|---|
| 21 | day: "numeric",
|
|---|
| 22 | });
|
|---|
| 23 |
|
|---|
| 24 | export const formatDateTime = (dateString: string | Date) =>
|
|---|
| 25 | new Date(dateString).toLocaleString("en-US", {
|
|---|
| 26 | year: "numeric",
|
|---|
| 27 | month: "short",
|
|---|
| 28 | day: "numeric",
|
|---|
| 29 | hour: "2-digit",
|
|---|
| 30 | minute: "2-digit",
|
|---|
| 31 | });
|
|---|
| 32 |
|
|---|
| 33 | export const getMonthName = (year: number, month: number) =>
|
|---|
| 34 | new Date(year, month - 1, 1).toLocaleDateString("en-US", {
|
|---|
| 35 | month: "long",
|
|---|
| 36 | year: "numeric",
|
|---|
| 37 | });
|
|---|
| 38 |
|
|---|
| 39 | export const dateToString = (date: Date): string => {
|
|---|
| 40 | const year = date.getFullYear();
|
|---|
| 41 | const month = String(date.getMonth() + 1).padStart(2, "0");
|
|---|
| 42 | const day = String(date.getDate()).padStart(2, "0");
|
|---|
| 43 |
|
|---|
| 44 | return `${year}-${month}-${day}`;
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | export const getTodayString = (): string => dateToString(new Date());
|
|---|
| 48 |
|
|---|
| 49 | export const isFutureDate = (date: Date | null): boolean => {
|
|---|
| 50 | if (!date) return false;
|
|---|
| 51 | const dateStr = dateToString(date);
|
|---|
| 52 | const todayStr = getTodayString();
|
|---|
| 53 | return dateStr > todayStr;
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | export const isTodayDate = (date: Date | null): boolean => {
|
|---|
| 57 | if (!date) return false;
|
|---|
| 58 | const dateStr = dateToString(date);
|
|---|
| 59 | const todayStr = getTodayString();
|
|---|
| 60 | return dateStr === todayStr;
|
|---|
| 61 | };
|
|---|