Fixed the time not showing on the project card issue

This commit is contained in:
NasSharaf 2025-06-12 22:39:55 -04:00
parent 4512ef1d8a
commit ad292ef1fa

View File

@ -43,22 +43,66 @@ const ProjectStatusDot = ({ status }: { status: ProjectStatus }) => {
* ProjectDeploymentInfo component * ProjectDeploymentInfo component
*/ */
const ProjectDeploymentInfo = ({ project }: { project: any }) => { const ProjectDeploymentInfo = ({ project }: { project: any }) => {
// Get formatted time // Get formatted time with robust error handling
const getTimeDisplay = (dateStr?: string): string => { const getTimeDisplay = (dateStr?: string | number | Date): string => {
if (!dateStr) return ''; if (!dateStr) return 'No date';
const date = new Date(dateStr); try {
const now = new Date(); // Handle different input types
const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60)); let date: Date;
if (diffInHours < 1) { if (dateStr instanceof Date) {
const diffInMinutes = Math.floor((now.getTime() - date.getTime()) / (1000 * 60)); date = dateStr;
return `${diffInMinutes} minutes ago`; } else if (typeof dateStr === 'number') {
} else if (diffInHours < 24) { date = new Date(dateStr);
return `${diffInHours} hours ago`; } else if (typeof dateStr === 'string') {
} else { // Handle various string formats
const diffInDays = Math.floor(diffInHours / 24); date = new Date(dateStr);
return `${diffInDays} days ago`;
// If the string date is invalid, try parsing as timestamp
if (isNaN(date.getTime())) {
const timestamp = parseInt(dateStr, 10);
if (!isNaN(timestamp)) {
date = new Date(timestamp);
}
}
} else {
return 'Invalid date';
}
// Check if date is valid
if (isNaN(date.getTime())) {
console.warn('Invalid date received:', dateStr);
return 'Invalid date';
}
const now = new Date();
const diffInMs = now.getTime() - date.getTime();
// Handle future dates
if (diffInMs < 0) {
return 'Future date';
}
const diffInMinutes = Math.floor(diffInMs / (1000 * 60));
const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60));
const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24));
if (diffInMinutes < 1) {
return 'Just now';
} else if (diffInMinutes < 60) {
return `${diffInMinutes} minute${diffInMinutes === 1 ? '' : 's'} ago`;
} else if (diffInHours < 24) {
return `${diffInHours} hour${diffInHours === 1 ? '' : 's'} ago`;
} else if (diffInDays < 30) {
return `${diffInDays} day${diffInDays === 1 ? '' : 's'} ago`;
} else {
// For dates older than 30 days, show the actual date
return date.toLocaleDateString();
}
} catch (error) {
console.error('Error parsing date:', dateStr, error);
return 'Invalid date';
} }
}; };