diff --git a/apps/deploy-fe/src/components/projects/project/ProjectCard/FixedProjectCard.tsx b/apps/deploy-fe/src/components/projects/project/ProjectCard/FixedProjectCard.tsx index 43880c4..40d9a32 100644 --- a/apps/deploy-fe/src/components/projects/project/ProjectCard/FixedProjectCard.tsx +++ b/apps/deploy-fe/src/components/projects/project/ProjectCard/FixedProjectCard.tsx @@ -43,22 +43,66 @@ const ProjectStatusDot = ({ status }: { status: ProjectStatus }) => { * ProjectDeploymentInfo component */ const ProjectDeploymentInfo = ({ project }: { project: any }) => { - // Get formatted time - const getTimeDisplay = (dateStr?: string): string => { - if (!dateStr) return ''; + // Get formatted time with robust error handling + const getTimeDisplay = (dateStr?: string | number | Date): string => { + if (!dateStr) return 'No date'; - const date = new Date(dateStr); - const now = new Date(); - const diffInHours = Math.floor((now.getTime() - date.getTime()) / (1000 * 60 * 60)); - - if (diffInHours < 1) { - const diffInMinutes = Math.floor((now.getTime() - date.getTime()) / (1000 * 60)); - return `${diffInMinutes} minutes ago`; - } else if (diffInHours < 24) { - return `${diffInHours} hours ago`; - } else { - const diffInDays = Math.floor(diffInHours / 24); - return `${diffInDays} days ago`; + try { + // Handle different input types + let date: Date; + + if (dateStr instanceof Date) { + date = dateStr; + } else if (typeof dateStr === 'number') { + date = new Date(dateStr); + } else if (typeof dateStr === 'string') { + // Handle various string formats + date = new Date(dateStr); + + // 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'; } };