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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | 6x 6x 3x 3x 1x 2x 2x 1x 1x 1x 6x 6x 3x 3x 1x 2x 2x 2x 2x 2x 8x 8x 3x 3x 3x 3x 3x 3x 1x 2x 1x 6x 6x 6x 5x 5x 2x 2x 1x 1x 645x 645x 645x 645x 645x 11x 11x 10x 10x 9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 2x 2x 2x 7x | /**
* Format a date string into a human-readable format.
*
* - If `hideTime` is true, only the date will be returned in the format "Dec 26, 2025".
* - If `hideTime` is false or not provided, both time and date are returned in the format "10:30 AM, Dec 26, 2025".
*
* @param input - The ISO date string to format (e.g., "2025-11-07T10:30:00.000Z").
* @param hideTime - Optional boolean flag to hide the time. Default is false.
* @returns A formatted string representing the date, optionally including time.
*/
export const formatDateTime = (input: string | number | Date, hideTime = true): string => {
if (!input) return "";
const date = new Date(input);
if (isNaN(date.getTime())) {
return "";
}
const day = date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
});
if (hideTime) {
return day;
}
const time = date.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
});
return `${time}, ${day}`;
};
/**
* Format date with weekday and optionally hide year if it's the current year.
*
* Examples:
* - Fri, Nov 19
* - Fri, Nov 19, 2024
*/
export const formatDateWithWeekday = (input: string | number | Date): string => {
if (!input) return "";
const date = new Date(input);
if (isNaN(date.getTime())) {
return "";
}
const now = new Date();
const isCurrentYear = date.getFullYear() === now.getFullYear();
const baseFormat: Intl.DateTimeFormatOptions = {
weekday: "short",
month: "short",
day: "numeric",
};
const withYearFormat: Intl.DateTimeFormatOptions = {
...baseFormat,
year: "numeric",
};
return date.toLocaleDateString("en-US", isCurrentYear ? baseFormat : withYearFormat);
};
/**
* Format days off value for display.
*
* Examples:
* - 1 Day off
* - 0.5 Day off
*/
export const formatDaysOff = (daysOff: number, startTime?: Date): string => {
// Special case: half day
if (daysOff === 0.5 && startTime) {
const hour = startTime.getHours();
const minute = startTime.getMinutes();
const totalMinutes = hour * 60 + minute;
const MORNING_START = 8 * 60; // 08:00
const AFTERNOON_START = 13 * 60 + 30; // 13:30
if (totalMinutes === MORNING_START) {
return "morning off";
}
if (totalMinutes === AFTERNOON_START) {
return "afternoon off";
}
}
const roundedValue =
daysOff % 1 === 0 ? daysOff.toString() : Number(daysOff.toFixed(1)).toString();
const dayLabel = daysOff === 1 ? "Day" : "Days";
return `${roundedValue} ${dayLabel} off`;
};
/**
* Format time only in 12-hour format with AM/PM.
*
* Examples:
* - 8:00 AM
* - 9:45 AM
* - 6:30 PM
*/
export const formatTime = (input: string | number | Date): string => {
if (!input) return "";
const date = new Date(input);
if (isNaN(date.getTime())) {
return "";
}
return date.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
});
};
/**
* Format a given date to the YYYY-MM-DD format.
*
* @param date - The date to format.
* @returns A string representing the formatted date in YYYY-MM-DD format.
*/
export const formatDateToYMD = (date: Date): string => {
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");
const d = String(date.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
};
type DateFormatVariant = "full" | "short";
export const formatMoveDate = (
inputDate: Date | string | undefined,
variant: DateFormatVariant = "full",
) => {
if (!inputDate) return "";
const date = typeof inputDate === "string" ? new Date(inputDate) : inputDate;
if (isNaN(date.getTime())) return "";
const weekdaysFull = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const weekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const monthsFull = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const monthsShort = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
const hours = date.getUTCHours();
const isMorning = hours < 4;
const session = isMorning ? "Morning" : "Afternoon";
const year = date.getFullYear();
if (variant === "short") {
// Trả về định dạng cho UI nhỏ: "Tue, Nov 25, 2025 • Morning"
const day = weekdaysShort[date.getDay()];
const month = monthsShort[date.getMonth()];
const dateNum = date.getDate();
return `${day}, ${month} ${dateNum}, ${year} • ${session}`;
}
// Mặc định trả về định dạng cũ: "Tuesday morning, November 25, 2025"
return `${weekdaysFull[date.getDay()]} ${session.toLowerCase()}, ${monthsFull[date.getMonth()]} ${date.getDate()}, ${year}`;
};
|