🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor DateSelector component to improve date formatting logic
Bill Yange2a9184b0f06
diff --git a/client/src/components/DateSelector/DateSelector.tsx b/client/src/components/DateSelector/DateSelector.tsxindex 7132c8659..676226321 100644--- a/client/src/components/DateSelector/DateSelector.tsx+++ b/client/src/components/DateSelector/DateSelector.tsx@@ -92,15 +92,20 @@ export function DateSelector({const start = DateTime.fromISO(`${time.startDate}T${time.startTime}`, { zone: tz });const endExclusive = DateTime.fromISO(`${time.endDate}T${time.endTime}`, { zone: tz });const displayEnd = stepDateTimeBucket(endExclusive, bucket, -1);+ const end = displayEnd > start ? displayEnd : endExclusive;const startFormatted = start.toFormat(hour12 ? "MMM d, h:mm a" : "MMM d, HH:mm");- const endFormatted = (displayEnd > start ? displayEnd : endExclusive).toFormat(- hour12 ? "MMM d, h:mm a" : "MMM d, HH:mm"- );+ const endFormatted =+ start.toISODate() === end.toISODate()+ ? end.toFormat(hour12 ? "h:mm a" : "HH:mm")+ : end.toFormat(hour12 ? "MMM d, h:mm a" : "MMM d, HH:mm");return `${startFormatted} - ${endFormatted}`;}- const startFormatted = DateTime.fromISO(time.startDate).toFormat("EEEE, MMM d");- const endFormatted = DateTime.fromISO(time.endDate).toFormat("EEEE, MMM d");+ const start = DateTime.fromISO(time.startDate);+ const end = DateTime.fromISO(time.endDate);+ const startFormatted = start.toFormat("EEEE, MMM d");+ if (start.toISODate() === end.toISODate()) return startFormatted;+ const endFormatted = end.toFormat("EEEE, MMM d");return `${startFormatted} - ${endFormatted}`;}