Update dependencies and enhance UptimeStatusIsland component with timezone and locale handling
- Added luxon library for improved date handling. - Updated UptimeStatusIsland component to format and display local time for heartbeats. - Enhanced state management to track user timezone and locale. - Ensured UTC formatting for timestamps in API responses.
This commit is contained in:
@@ -7,7 +7,7 @@ const STATUS_PAGE_SLUG = '365devnet'; // all lowercase
|
||||
|
||||
interface Heartbeat {
|
||||
status: number; // 0=DOWN, 1=UP, 2=PENDING, 3=MAINTENANCE
|
||||
time: string;
|
||||
time: string; // UTC ISO string
|
||||
msg: string;
|
||||
ping: number | null;
|
||||
important?: boolean;
|
||||
@@ -28,7 +28,7 @@ interface Monitor {
|
||||
uptimePercent?: number;
|
||||
currentPing?: number;
|
||||
avgPing?: number;
|
||||
lastChecked?: string;
|
||||
lastChecked?: string; // UTC ISO string
|
||||
uptime24h?: number;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,12 @@ const fetchWithTimeout = async (url: string, options: RequestInit, timeout = 100
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to ensure a date string is in UTC ISO format
|
||||
function ensureUTC(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toISOString();
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
try {
|
||||
if (!UPTIME_KUMA_URL) {
|
||||
@@ -107,7 +113,11 @@ export const GET: APIRoute = async () => {
|
||||
for (const group of data.publicGroupList) {
|
||||
for (const monitor of group.monitorList) {
|
||||
const hbArr = heartbeatList[monitor.id.toString()] || [];
|
||||
monitor.heartbeatHistory = hbArr;
|
||||
// Ensure all heartbeat times are in UTC
|
||||
monitor.heartbeatHistory = hbArr.map(hb => ({
|
||||
...hb,
|
||||
time: ensureUTC(hb.time)
|
||||
}));
|
||||
// Uptime % (last 40 heartbeats)
|
||||
if (hbArr.length > 0) {
|
||||
const last40 = hbArr.slice(-40);
|
||||
@@ -118,8 +128,8 @@ export const GET: APIRoute = async () => {
|
||||
// Average ping (last 40 heartbeats)
|
||||
const pings = last40.map(hb => hb.ping).filter(p => typeof p === 'number') as number[];
|
||||
monitor.avgPing = pings.length > 0 ? Math.round((pings.reduce((a, b) => a + b, 0) / pings.length) * 10) / 10 : undefined;
|
||||
// Last checked
|
||||
monitor.lastChecked = last40[last40.length - 1]?.time ?? undefined;
|
||||
// Last checked (ensure UTC)
|
||||
monitor.lastChecked = last40[last40.length - 1]?.time ? ensureUTC(last40[last40.length - 1].time) : undefined;
|
||||
} else {
|
||||
monitor.uptimePercent = undefined;
|
||||
monitor.currentPing = undefined;
|
||||
|
||||
Reference in New Issue
Block a user