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:
@@ -1,14 +1,46 @@
|
||||
import { I18N } from 'astrowind:config';
|
||||
|
||||
// Format dates in user's local timezone
|
||||
export const formatter: Intl.DateTimeFormat = new Intl.DateTimeFormat(I18N?.language, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
timeZoneName: 'short',
|
||||
});
|
||||
|
||||
// Format dates in user's local timezone with full date and time
|
||||
export const fullDateFormatter: Intl.DateTimeFormat = new Intl.DateTimeFormat(I18N?.language, {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
timeZoneName: 'short',
|
||||
});
|
||||
|
||||
export const getFormattedDate = (date: Date): string => (date ? formatter.format(date) : '');
|
||||
|
||||
export const getFullFormattedDate = (date: Date): string => (date ? fullDateFormatter.format(date) : '');
|
||||
|
||||
// Get user's timezone
|
||||
export const getUserTimezone = (): string => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
return 'UTC';
|
||||
};
|
||||
|
||||
// Get user's locale
|
||||
export const getUserLocale = (): string => {
|
||||
if (typeof window !== 'undefined') {
|
||||
return navigator.language;
|
||||
}
|
||||
return I18N?.language || 'en';
|
||||
};
|
||||
|
||||
export const trim = (str = '', ch?: string) => {
|
||||
let start = 0,
|
||||
end = str.length || 0;
|
||||
|
Reference in New Issue
Block a user