This commit is contained in:
2025-06-10 01:57:19 +02:00
parent b4fe29413b
commit 662f22a58f
3 changed files with 115 additions and 37 deletions

View File

@@ -1085,35 +1085,48 @@ const updateBerthRecommendations = async (newRecommendations: number[]) => {
// Format date helper function
const formatDate = (dateString: string | null | undefined) => {
if (!dateString) return "";
try {
let date: Date;
// Check if it's an ISO date string (e.g., "2025-06-09T22:58:47.731Z")
if (dateString.includes('T') || dateString.includes('Z')) {
date = new Date(dateString);
}
// Handle DD-MM-YYYY format
if (dateString.includes("-")) {
const parts = dateString.split("-");
if (parts.length === 3) {
const [day, month, year] = parts;
const date = new Date(
parseInt(year),
parseInt(month) - 1,
parseInt(day)
);
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
}
else if (dateString.match(/^\d{2}-\d{2}-\d{4}$/)) {
const [day, month, year] = dateString.split("-");
date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
}
// Fallback to direct date parsing
const date = new Date(dateString);
if (!isNaN(date.getTime())) {
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
// Handle YYYY-MM-DD format
else if (dateString.match(/^\d{4}-\d{2}-\d{2}$/)) {
date = new Date(dateString);
}
return dateString;
// Fallback to direct parsing
else {
date = new Date(dateString);
}
// Check if date is valid
if (isNaN(date.getTime())) {
return dateString;
}
// Format date in DD/MM/YYYY HH:mm format
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
// Include time if it's not midnight
if (hours !== '00' || minutes !== '00') {
return `${day}/${month}/${year} ${hours}:${minutes}`;
}
return `${day}/${month}/${year}`;
} catch (error) {
console.error('Date formatting error:', error, dateString);
return dateString;
}
};