22 lines
735 B
TypeScript
22 lines
735 B
TypeScript
import { utcDay } from "./utcDay"
|
||
|
||
/** Compact date range between two ISO datetimes, e.g. "13 – 14 juin 2026"
|
||
* (same month), "13 juin 2026" (same day), or full "… – …" otherwise. */
|
||
export const formatDateRange = (startIso: string, endIso: string): string => {
|
||
const a = utcDay(startIso)
|
||
const b = utcDay(endIso)
|
||
const full = (d: Date) =>
|
||
new Intl.DateTimeFormat("fr-FR", {
|
||
day: "numeric",
|
||
month: "long",
|
||
year: "numeric",
|
||
timeZone: "UTC",
|
||
}).format(d)
|
||
if (a.getTime() === b.getTime()) return full(a)
|
||
if (
|
||
a.getUTCFullYear() === b.getUTCFullYear() &&
|
||
a.getUTCMonth() === b.getUTCMonth()
|
||
)
|
||
return `${a.getUTCDate()} – ${full(b)}`
|
||
return `${full(a)} – ${full(b)}`
|
||
}
|