Adjusted context to hopefully reflect accurate timezones relative to browser.
All checks were successful
Deploy Frontend / deploy (push) Successful in 40s

This commit is contained in:
Bailey Taylor
2025-10-08 08:03:54 +08:00
parent ac2c3ce6a9
commit 67334a65d8
5 changed files with 52 additions and 8 deletions

View File

@@ -32,14 +32,24 @@ const ONLINE_THRESHOLD_MINUTES = 1440;
function getStatusColor(lastCheckedIn: string) {
const lastSeen = parseISO(lastCheckedIn);
// Parse UTC timestamp and treat it correctly as UTC
const lastSeen = new Date(lastCheckedIn + 'Z'); // Add Z to indicate UTC
const minutesAgo = (Date.now() - lastSeen.getTime()) / 1000 / 60;
return minutesAgo < ONLINE_THRESHOLD_MINUTES ? 'green' : 'grey';
}
function formatRelativeTime(lastCheckedIn: string) {
try {
return formatDistanceToNowStrict(parseISO(lastCheckedIn), { addSuffix: true });
// Parse UTC timestamp and treat it correctly as UTC
const lastSeen = new Date(lastCheckedIn + 'Z'); // Add Z to indicate UTC
// Debug: Log what we're getting vs what we should get
//const wrongWay = new Date(lastCheckedIn); // Without Z - treats as local
//console.log(`🕒 DEBUG: "${lastCheckedIn}"`);
//console.log(`🕒 Wrong way (as local): ${wrongWay.toLocaleString()} -> ${formatDistanceToNowStrict(wrongWay, { addSuffix: true })}`);
//console.log(`🕒 Right way (as UTC): ${lastSeen.toLocaleString()} -> ${formatDistanceToNowStrict(lastSeen, { addSuffix: true })}`);
return formatDistanceToNowStrict(lastSeen, { addSuffix: true });
} catch {
return 'Unknown';
}
@@ -56,7 +66,7 @@ const DeviceListSidebar: React.FC<DeviceListSidebarProps> = ({
onTogglePin,
}) => {
const [sortAsc, setSortAsc] = React.useState(true);
const [searchQuery, setSearchQuery] = React.useState('');
const [searchQuery, setSearchQuery] = React.useState('');

View File

@@ -81,11 +81,12 @@ export default function DeviceTableSection({ initialDevices }: Props) {
const formatLastCheckedIn = (isoString: string): string => {
const date = new Date(isoString);
// Parse as UTC by adding 'Z' if not present
const date = new Date(isoString + (isoString.includes('Z') || isoString.includes('+') ? '' : 'Z'));
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const formatted = date.toLocaleString('en-AU', {
day: '2-digit',
month: '2-digit',
@@ -94,7 +95,7 @@ export default function DeviceTableSection({ initialDevices }: Props) {
minute: '2-digit',
hour12: true,
});
return `${formatted} (${diffHours} hours ago)`;
};

View File

@@ -127,7 +127,16 @@ export default function DevicesClient() {
const formatBootTime = (timestamp: string) => {
try {
const parsed = parseISO(timestamp);
// Handle timestamp - could be UTC or already have timezone info
let parsed: Date;
if (timestamp.includes('+') || timestamp.endsWith('Z')) {
// Already has timezone info, parse directly
parsed = new Date(timestamp);
} else {
// Assume UTC, add Z to indicate UTC
parsed = new Date(timestamp + 'Z');
}
const formattedDate = format(parsed, 'EEEE do MMMM yyyy');
const relative = formatDistanceToNowStrict(parsed, { addSuffix: true });
return `${formattedDate} (${relative})`;

View File

@@ -7,6 +7,13 @@ import { DetailedDevice } from '@/types/devices';
import { disableConsoleInProd } from '@/lib/disableConsole';
disableConsoleInProd();
// Helper function to convert UTC timestamps to local time
const convertUtcToLocal = (utcString: string | null): string | null => {
if (!utcString) return null;
// Add 'Z' to indicate it's UTC, then convert to local time
return new Date(utcString + 'Z').toLocaleString();
};
interface DriveInfo {
@@ -125,7 +132,7 @@ export const DeviceProvider = ({
console.log('✅ Software fetched:', softwareRes.data);
console.groupEnd();
// STEP 1: Set basic data
// STEP 1: Set basic data (keep original UTC timestamps for calculations)
setDevices(devicesRes.data.devices);
setDeviceVulns(devicesRes.data.vulnerabilitiesByDevice);
setCachedSoftware(softwareRes.data);