diff --git a/www/js/metrics/MetricsDateSelect.tsx b/www/js/metrics/MetricsDateSelect.tsx index fa1aaed3e..014b5a00c 100644 --- a/www/js/metrics/MetricsDateSelect.tsx +++ b/www/js/metrics/MetricsDateSelect.tsx @@ -35,11 +35,24 @@ const MetricsDateSelect = ({ dateRange, setDateRange }: Props) => { const onChoose = useCallback( ({ startDate, endDate }) => { + const dtStartDate = DateTime.fromJSDate(startDate).startOf('day'); + let dtEndDate; + + if (!endDate) { + // If no end date selected, pull range from then till present day + dtEndDate = DateTime.now(); + } else if ( + dtStartDate.toString() === DateTime.fromJSDate(endDate).startOf('day').toString() + ) { + // For when only one day is selected + // NOTE: As written, this technically timestamp will technically fetch _two_ days. + // For more info, see: https://github.com/e-mission/e-mission-docs/issues/1027 + dtEndDate = dtStartDate.endOf('day'); + } else { + dtEndDate = DateTime.fromJSDate(endDate).startOf('day'); + } setOpen(false); - setDateRange([ - DateTime.fromJSDate(startDate).startOf('day'), - DateTime.fromJSDate(endDate).startOf('day'), - ]); + setDateRange([dtStartDate, dtEndDate]); }, [setOpen, setDateRange], );