Skip to content

Commit 5c67061

Browse files
committed
More reliable date parsing if seconds not ms
1 parent c05fc0d commit 5c67061

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

apps/webapp/app/components/code/QueryResultsChart.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,23 @@ function tryParseDate(value: unknown): Date | null {
170170
return isNaN(date.getTime()) ? null : date;
171171
}
172172
if (typeof value === "number") {
173-
// Could be a timestamp
174-
const date = new Date(value);
175-
// Sanity check: should be between 1970 and 2100
176-
if (date.getFullYear() >= 1970 && date.getFullYear() <= 2100) {
177-
return date;
173+
// First, try treating the number as milliseconds
174+
const dateAsMs = new Date(value);
175+
if (
176+
!isNaN(dateAsMs.getTime()) &&
177+
dateAsMs.getFullYear() >= 1970 &&
178+
dateAsMs.getFullYear() <= 2100
179+
) {
180+
return dateAsMs;
181+
}
182+
// If that fails, try treating the number as seconds (Unix timestamp)
183+
const dateAsSec = new Date(value * 1000);
184+
if (
185+
!isNaN(dateAsSec.getTime()) &&
186+
dateAsSec.getFullYear() >= 1970 &&
187+
dateAsSec.getFullYear() <= 2100
188+
) {
189+
return dateAsSec;
178190
}
179191
}
180192
return null;

0 commit comments

Comments
 (0)