Skip to content

Open-source status page, incident response and uptime monitoring

fix: wrong date (#185)

Maximilian Kaskeaa612ca41bba
diff --git a/apps/web/src/components/data-table/data-table-date-ranger-picker.tsx b/apps/web/src/components/data-table/data-table-date-ranger-picker.tsx
index d5b71262a..06da1ba29 100644
--- a/apps/web/src/components/data-table/data-table-date-ranger-picker.tsx
+++ b/apps/web/src/components/data-table/data-table-date-ranger-picker.tsx
@@ -2,7 +2,7 @@
import * as React from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
-import { format } from "date-fns";
+import { addDays, format } from "date-fns";
import { Calendar as CalendarIcon } from "lucide-react";
import type { DateRange } from "react-day-picker";
@@ -49,7 +49,7 @@ export function DataTableDateRangePicker({
id="date"
variant="outline"
className={cn(
- "w-[250px] justify-start text-left font-normal",
+ "w-[260px] justify-start text-left font-normal",
!date && "text-muted-foreground",
)}
>
@@ -74,11 +74,13 @@ export function DataTableDateRangePicker({
mode="range"
defaultMonth={date?.from}
selected={date}
- onSelect={(e) => {
- setDate(e);
+ onSelect={(value) => {
+ setDate(value);
+ const { fromDate, toDate } = manipulateDate(value);
+
const searchParams = updateSearchParams({
- fromDate: e?.from?.getTime() || null,
- toDate: e?.to?.getTime() || null,
+ fromDate,
+ toDate,
});
router.replace(`${pathname}?${searchParams}`);
}}
@@ -88,3 +90,20 @@ export function DataTableDateRangePicker({
</div>
);
}
+
+/**
+ * Whenever you select a date, it will use the midnight timestamp of that date.
+ * We need to add a day minus one second to include the whole day.
+ */
+function manipulateDate(date?: DateRange | null) {
+ const isToDateMidnight = String(date?.to?.getTime()).endsWith("00000");
+
+ const addOneDayToDate = date?.to
+ ? addDays(new Date(date.to), 1).getTime() - 1
+ : null;
+
+ return {
+ fromDate: date?.from?.getTime() || null,
+ toDate: isToDateMidnight ? addOneDayToDate : date?.to?.getTime() || null,
+ };
+}
diff --git a/apps/web/src/components/data-table/data-table-toolbar.tsx b/apps/web/src/components/data-table/data-table-toolbar.tsx
index 802b16808..13c2a6274 100644
--- a/apps/web/src/components/data-table/data-table-toolbar.tsx
+++ b/apps/web/src/components/data-table/data-table-toolbar.tsx
@@ -26,14 +26,13 @@ export function DataTableToolbar<TData>({
<DataTableFacetedFilter
column={table.getColumn("region")}
title="Region"
- options={Object.keys(regionsDict).map((key) => ({
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-expect-error
- label: regionsDict[key].location,
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-expect-error
- value: regionsDict[key].code,
- }))}
+ options={Object.keys(regionsDict).map((key) => {
+ const typedKey = key as keyof typeof regionsDict;
+ return {
+ label: regionsDict[typedKey].location,
+ value: regionsDict[typedKey].code,
+ };
+ })}
/>
)}
{isFiltered && (