Enhance date formatting in UptimeStatusIsland and ensure UTC compliance in API

- Improved the formatLocalTime function to handle various date formats and ensure accurate timezone conversion.
- Updated the ensureUTC function to check for ISO format and append 'Z' for UTC interpretation when necessary.
This commit is contained in:
2025-07-07 20:07:07 +02:00
parent 63f5c24590
commit 658881124f
2 changed files with 70 additions and 7 deletions

View File

@@ -58,7 +58,13 @@ 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);
// If it's already in ISO format with Z, return as-is
if (dateString.endsWith('Z') || dateString.includes('+') || dateString.includes('T') && dateString.includes(':')) {
return dateString;
}
// If it's a simple date string, force UTC interpretation
const date = new Date(dateString + 'Z');
return date.toISOString();
}
@@ -163,4 +169,4 @@ export const GET: APIRoute = async () => {
},
});
}
};
};