feat: Add date formatting utility functions and integrate them across components

This commit is contained in:
Chop
2025-06-19 23:29:06 +02:00
parent 306c96328e
commit 639179ed21
11 changed files with 118 additions and 74 deletions

View File

@@ -1,40 +1,90 @@
// Test utilities for deadline and status formatting
export const getDeadlineVariant = (days) => {
if (days < 0) return "danger";
if (days <= 7) return "warning";
return "success";
if (days < 0) return "danger";
if (days <= 7) return "warning";
return "success";
};
export const formatProjectStatus = (status) => {
switch (status) {
case "registered":
return "Zarejestrowany";
case "in_progress_design":
return "W realizacji (projektowanie)";
case "in_progress_construction":
return "W realizacji (realizacja)";
case "fulfilled":
return "Zakończony";
default:
return "-";
}
switch (status) {
case "registered":
return "Zarejestrowany";
case "in_progress_design":
return "W realizacji (projektowanie)";
case "in_progress_construction":
return "W realizacji (realizacja)";
case "fulfilled":
return "Zakończony";
default:
return "-";
}
};
export const formatProjectType = (type) => {
switch (type) {
case "design":
return "Projektowanie";
case "construction":
return "Realizacja";
case "design+construction":
return "Projektowanie + Realizacja";
default:
return "-";
}
switch (type) {
case "design":
return "Projektowanie";
case "construction":
return "Realizacja";
case "design+construction":
return "Projektowanie + Realizacja";
default:
return "-";
}
};
export const getDeadlineText = (daysRemaining) => {
if (daysRemaining === 0) return "Due Today";
if (daysRemaining > 0) return `${daysRemaining} days left`;
return `${Math.abs(daysRemaining)} days overdue`;
if (daysRemaining === 0) return "Due Today";
if (daysRemaining > 0) return `${daysRemaining} days left`;
return `${Math.abs(daysRemaining)} days overdue`;
};
export const formatDate = (date, options = {}) => {
if (!date) return "";
try {
const dateObj = typeof date === "string" ? new Date(date) : date;
if (isNaN(dateObj.getTime())) {
return "Invalid date";
}
// Default to DD.MM.YYYY format
const day = String(dateObj.getDate()).padStart(2, "0");
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
const year = dateObj.getFullYear();
if (options.includeTime) {
const hours = String(dateObj.getHours()).padStart(2, "0");
const minutes = String(dateObj.getMinutes()).padStart(2, "0");
return `${day}.${month}.${year} ${hours}:${minutes}`;
}
return `${day}.${month}.${year}`;
} catch (error) {
console.error("Error formatting date:", error);
return "Invalid date";
}
};
export const formatDateForInput = (date) => {
if (!date) return "";
try {
const dateObj = typeof date === "string" ? new Date(date) : date;
if (isNaN(dateObj.getTime())) {
return "";
}
// Format as YYYY-MM-DD for HTML date inputs
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
const day = String(dateObj.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
} catch (error) {
console.error("Error formatting date for input:", error);
return "";
}
};