Update package-lock.json and enhance UptimeStatusIsland component for time formatting
- Updated package-lock.json to reflect new versions of dependencies, including luxon for date handling. - Modified UptimeStatusIsland component to improve local time formatting, ensuring UTC display and handling of invalid dates.
This commit is contained in:
5192
package-lock.json
generated
5192
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -44,11 +44,12 @@ function getUptime24hBg(uptime) {
|
|||||||
return 'bg-red-600 text-white dark:bg-red-800 dark:text-white';
|
return 'bg-red-600 text-white dark:bg-red-800 dark:text-white';
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLocalTime(utcTime) {
|
function formatLocalTime(rawTime) {
|
||||||
if (!utcTime) return '';
|
if (!rawTime) return '';
|
||||||
const dt = DateTime.fromISO(utcTime, { zone: 'utc' });
|
// Parse the API's custom format as UTC
|
||||||
|
const dt = DateTime.fromFormat(rawTime, 'yyyy-MM-dd HH:mm:ss.SSS', { zone: 'utc' });
|
||||||
// Always show in UTC, format: dd-MM-yyyy, HH:mm:ss UTC
|
// Always show in UTC, format: dd-MM-yyyy, HH:mm:ss UTC
|
||||||
return dt.toFormat('dd-MM-yyyy, HH:mm:ss') + ' UTC';
|
return dt.isValid ? dt.toFormat('dd-MM-yyyy, HH:mm:ss') + ' UTC' : 'Invalid DateTime UTC';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function UptimeStatusIsland() {
|
export default function UptimeStatusIsland() {
|
||||||
|
@@ -3,6 +3,7 @@ export const prerender = true;
|
|||||||
import Layout from '~/layouts/PageLayout.astro';
|
import Layout from '~/layouts/PageLayout.astro';
|
||||||
import StructuredData from '~/components/common/StructuredData.astro';
|
import StructuredData from '~/components/common/StructuredData.astro';
|
||||||
import Hero from '~/components/widgets/Hero.astro';
|
import Hero from '~/components/widgets/Hero.astro';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import { getTranslation, supportedLanguages } from '~/i18n/translations';
|
import { getTranslation, supportedLanguages } from '~/i18n/translations';
|
||||||
|
|
||||||
@@ -37,6 +38,24 @@ const tocItems = [
|
|||||||
{ id: 'changes', title: 'Changes to Privacy Policy' },
|
{ id: 'changes', title: 'Changes to Privacy Policy' },
|
||||||
{ id: 'contact', title: 'Contact Information' },
|
{ id: 'contact', title: 'Contact Information' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Helper function to parse and format heartbeat times in UTC
|
||||||
|
function parseAndFormatTime(rawTime) {
|
||||||
|
const dt = DateTime.fromFormat(rawTime, 'yyyy-MM-dd HH:mm:ss.SSS', { zone: 'utc' });
|
||||||
|
return dt.isValid ? dt.toFormat('dd-LL-yyyy, HH:mm:ss \"UTC\"') : 'Invalid DateTime UTC';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage: format all heartbeats in all lists
|
||||||
|
// (Assume apiData is your fetched API data)
|
||||||
|
// const apiData = { heartbeatList: { ... } };
|
||||||
|
// const formattedHeartbeatList = Object.fromEntries(
|
||||||
|
// Object.entries(apiData.heartbeatList).map(([key, arr]) => [
|
||||||
|
// key,
|
||||||
|
// arr.map(hb => ({ ...hb, formattedTime: parseAndFormatTime(hb.time) }))
|
||||||
|
// ])
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// Now, for each heartbeat, use hb.formattedTime for display in UTC.
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout metadata={metadata}>
|
<Layout metadata={metadata}>
|
||||||
|
Reference in New Issue
Block a user