Fix awkward multi-day event date formatting
Same-month ranges were rendering as e.g. "Sat, Oct 10, 2026 – 11" (full start date, then a bare trailing day number for the end). Now: single day "Sat, Oct 17, 2026", same-month range "Oct 10–11, 2026", cross-month "Oct 30 – Nov 1, 2026", cross-year "Dec 30, 2026 – Jan 2, 2027". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SBzcNkW7JcYipnAX6HfgmK
This commit is contained in:
@@ -114,15 +114,25 @@ function esc(s) {
|
|||||||
|
|
||||||
function fmtDateRange(startIso, endIso) {
|
function fmtDateRange(startIso, endIso) {
|
||||||
const start = new Date(startIso);
|
const start = new Date(startIso);
|
||||||
const opts = { weekday: "short", month: "short", day: "numeric", year: "numeric" };
|
const end = endIso ? new Date(endIso) : null;
|
||||||
const startStr = start.toLocaleDateString(undefined, opts);
|
|
||||||
if (!endIso) return startStr;
|
// Single day: "Sat, Oct 17, 2026"
|
||||||
const end = new Date(endIso);
|
if (!end || start.toDateString() === end.toDateString()) {
|
||||||
if (start.toDateString() === end.toDateString()) return startStr;
|
return start.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric", year: "numeric" });
|
||||||
const sameMonth = start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
|
}
|
||||||
const endStr = sameMonth
|
|
||||||
? end.toLocaleDateString(undefined, { day: "numeric" })
|
const sameYear = start.getFullYear() === end.getFullYear();
|
||||||
: end.toLocaleDateString(undefined, opts);
|
const sameMonth = sameYear && start.getMonth() === end.getMonth();
|
||||||
|
|
||||||
|
// Same month: "Oct 10–11, 2026"
|
||||||
|
if (sameMonth) {
|
||||||
|
const month = start.toLocaleDateString(undefined, { month: "short" });
|
||||||
|
return `${month} ${start.getDate()}–${end.getDate()}, ${end.getFullYear()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Different month (or year): "Oct 30 – Nov 1, 2026" / "Dec 30, 2026 – Jan 2, 2027"
|
||||||
|
const startStr = start.toLocaleDateString(undefined, { month: "short", day: "numeric", year: sameYear ? undefined : "numeric" });
|
||||||
|
const endStr = end.toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" });
|
||||||
return `${startStr} – ${endStr}`;
|
return `${startStr} – ${endStr}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user