diff --git a/app/api/applications/uptime/route.ts b/app/api/applications/uptime/route.ts index e9dfc67..7c61f12 100644 --- a/app/api/applications/uptime/route.ts +++ b/app/api/applications/uptime/route.ts @@ -12,22 +12,27 @@ const getTimeRange = (timespan: number) => { switch (timespan) { case 1: return { - start: new Date(now.getTime() - 30 * 60 * 1000), + start: new Date(now.getTime() - 60 * 60 * 1000), interval: 'minute' }; case 2: return { - start: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000), - interval: '3hour' + start: new Date(now.getTime() - 24 * 60 * 60 * 1000), + interval: 'hour' }; case 3: + return { + start: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000), + interval: 'day' + }; + case 4: return { start: new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000), interval: 'day' }; default: return { - start: new Date(now.getTime() - 30 * 60 * 1000), + start: new Date(now.getTime() - 60 * 60 * 1000), interval: 'minute' }; } @@ -38,23 +43,31 @@ const generateIntervals = (timespan: number) => { now.setSeconds(0, 0); switch (timespan) { - case 1: - return Array.from({ length: 30 }, (_, i) => { + case 1: // 1 hour - 60 one-minute intervals + return Array.from({ length: 60 }, (_, i) => { const d = new Date(now); d.setMinutes(d.getMinutes() - i); d.setSeconds(0, 0); return d; }); - case 2: - return Array.from({ length: 56 }, (_, i) => { + case 2: // 1 day - 24 one-hour intervals + return Array.from({ length: 24 }, (_, i) => { const d = new Date(now); - d.setHours(d.getHours() - (i * 3)); + d.setHours(d.getHours() - i); d.setMinutes(0, 0, 0); return d; }); - case 3: + case 3: // 7 days + return Array.from({ length: 7 }, (_, i) => { + const d = new Date(now); + d.setDate(d.getDate() - i); + d.setHours(0, 0, 0, 0); + return d; + }); + + case 4: // 30 days return Array.from({ length: 30 }, (_, i) => { const d = new Date(now); d.setDate(d.getDate() - i); @@ -70,14 +83,14 @@ const generateIntervals = (timespan: number) => { const getIntervalKey = (date: Date, timespan: number) => { const d = new Date(date); switch (timespan) { - case 1: + case 1: // 1 hour - minute intervals d.setSeconds(0, 0); return d.toISOString(); - case 2: - d.setHours(Math.floor(d.getHours() / 3) * 3); + case 2: // 1 day - hour intervals d.setMinutes(0, 0, 0); return d.toISOString(); - case 3: + case 3: // 7 days - day intervals + case 4: // 30 days - day intervals d.setHours(0, 0, 0, 0); return d.toISOString(); default: diff --git a/app/dashboard/uptime/Uptime.tsx b/app/dashboard/uptime/Uptime.tsx index 6bc8d7e..74af4e6 100644 --- a/app/dashboard/uptime/Uptime.tsx +++ b/app/dashboard/uptime/Uptime.tsx @@ -34,14 +34,18 @@ const timeFormats = { minute: '2-digit', hour12: false }), - 2: (timestamp: string) => { - const start = new Date(timestamp); - const end = new Date(start.getTime() + 3 * 60 * 60 * 1000); - return `${start.toLocaleDateString([], { day: '2-digit', month: 'short' })} - ${start.getHours().toString().padStart(2, '0')}:00 - - ${end.getHours().toString().padStart(2, '0')}:00`; - }, + 2: (timestamp: string) => + new Date(timestamp).toLocaleTimeString([], { + hour: '2-digit', + minute: '2-digit', + hour12: false + }), 3: (timestamp: string) => + new Date(timestamp).toLocaleDateString([], { + day: '2-digit', + month: 'short' + }), + 4: (timestamp: string) => new Date(timestamp).toLocaleDateString([], { day: '2-digit', month: 'short' @@ -49,9 +53,10 @@ const timeFormats = { }; const minBoxWidths = { - 1: 24, - 2: 24, - 3: 24 + 1: 20, + 2: 20, + 3: 24, + 4: 24 }; interface UptimeData { @@ -72,7 +77,7 @@ interface PaginationData { export default function Uptime() { const [data, setData] = useState([]); - const [timespan, setTimespan] = useState<1 | 2 | 3>(1); + const [timespan, setTimespan] = useState<1 | 2 | 3 | 4>(1); const [pagination, setPagination] = useState({ currentPage: 1, totalPages: 1, @@ -153,7 +158,7 @@ export default function Uptime() { @@ -219,18 +225,14 @@ export default function Uptime() { >

- {timespan === 2 ? ( - timeFormats[2](entry.timestamp) - ) : ( - new Date(entry.timestamp).toLocaleString([], { - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: timespan === 3 ? undefined : '2-digit', - hour12: false - }) - )} + {new Date(entry.timestamp).toLocaleString([], { + year: 'numeric', + month: 'short', + day: timespan > 2 ? 'numeric' : undefined, + hour: '2-digit', + minute: timespan === 1 ? '2-digit' : undefined, + hour12: false + })}

{entry.missing