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:
@@ -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 () => {
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user