feat: Update date handling to use local time formatting across various components and queries

This commit is contained in:
2025-10-04 19:44:35 +02:00
parent 79238dd643
commit 119b03a7ba
9 changed files with 71 additions and 28 deletions

View File

@@ -51,14 +51,17 @@ export const formatDate = (date, options = {}) => {
return "Nieprawidłowa data";
}
// Convert to Polish timezone (Europe/Warsaw)
const polandTime = new Date(dateObj.toLocaleString("en-US", { timeZone: "Europe/Warsaw" }));
// 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();
const day = String(polandTime.getDate()).padStart(2, "0");
const month = String(polandTime.getMonth() + 1).padStart(2, "0");
const year = polandTime.getFullYear();
if (options.includeTime) {
const hours = String(dateObj.getHours()).padStart(2, "0");
const minutes = String(dateObj.getMinutes()).padStart(2, "0");
const hours = String(polandTime.getHours()).padStart(2, "0");
const minutes = String(polandTime.getMinutes()).padStart(2, "0");
return `${day}.${month}.${year} ${hours}:${minutes}`;
}
@@ -129,3 +132,27 @@ export const formatCoordinates = (coordinatesString) => {
return coordinatesString;
}
};
// Format timestamp for Polish timezone with full date and time
export const formatTimestamp = (timestamp) => {
if (!timestamp) return "";
try {
const date = new Date(timestamp);
if (isNaN(date.getTime())) {
return "Nieprawidłowa data";
}
return date.toLocaleString("pl-PL", {
timeZone: "Europe/Warsaw",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
});
} catch (error) {
console.error("Error formatting timestamp:", error);
return timestamp;
}
};