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 | 11x 11x 131x 131x 131x 131x 131x 131x 107x 24x 24x 24x 24x 24x 24x 24x 11x 30x 8x 8x 5x 3x | import i18n from '@/i18n';
export function formatEventDateLabel(
startTime: string,
endTime?: string | null,
): string {
const start = new Date(startTime);
const locale = i18n.language || 'en';
Iif (Number.isNaN(start.getTime())) {
return 'Invalid date';
}
const startDatePart = start.toLocaleDateString(locale, {
day: 'numeric',
month: 'short',
year: 'numeric',
});
const startTimePart = start.toLocaleTimeString(locale, {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
if (!endTime) {
return `${startDatePart} • ${startTimePart}`;
}
const end = new Date(endTime);
Iif (Number.isNaN(end.getTime())) {
return `${startDatePart} • ${startTimePart}`;
}
const endDatePart = end.toLocaleDateString(locale, {
day: 'numeric',
month: 'short',
year: 'numeric',
});
const endTimePart = end.toLocaleTimeString(locale, {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
const isSameDay =
start.getFullYear() === end.getFullYear() &&
start.getMonth() === end.getMonth() &&
start.getDate() === end.getDate();
if (isSameDay) {
return `${startDatePart} • ${startTimePart} - ${endTimePart}`;
}
return `${startDatePart} • ${startTimePart} - ${endDatePart} • ${endTimePart}`;
}
/**
* Returns the number of days remaining before an in-progress event without an
* end date is auto-completed (at the 60-day mark), or `null` when no warning
* should be displayed.
*
* A warning is shown between day 53 and day 59 (inclusive) since the event
* started.
*/
export function getAutoCompletionDaysLeft(
status: string,
startTime: string,
endTime?: string | null,
now: Date = new Date(),
): number | null {
if (status !== 'IN_PROGRESS' || endTime) return null;
const daysSinceStart = Math.floor(
(now.getTime() - new Date(startTime).getTime()) / (1000 * 60 * 60 * 24),
);
if (daysSinceStart >= 53 && daysSinceStart < 60) {
return 60 - daysSinceStart;
}
return null;
} |