rallly/apps/web/src/utils/get-range.ts
2024-10-05 21:11:55 +01:00

17 lines
493 B
TypeScript

import dayjs from "dayjs";
/**
* Get a range of dates in a human readable format
* If the start and end date are the same, return the start date
* @param start The start date
* @param end The end date
* @returns A human readable range of dates
*/
export function getRange(start: Date, end: Date) {
const startDay = dayjs(start).format("DD MMM");
const endDay = dayjs(end).format("DD MMM");
if (startDay === endDay) {
return startDay;
}
return `${startDay} - ${endDay}`;
}