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

@@ -68,7 +68,7 @@ async function createNoteHandler(req) {
.prepare(
`
INSERT INTO notes (project_id, task_id, note, created_by, note_date)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
VALUES (?, ?, ?, ?, datetime('now', 'localtime'))
`
)
.run(project_id || null, task_id || null, note, req.user?.id || null);

View File

@@ -746,7 +746,7 @@ export default function ProjectViewPage() {
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-gray-500">
{n.note_date}
{formatDate(n.note_date, { includeTime: true })}
</span>
{n.created_by_name && (
<span className="px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded-full font-medium">

View File

@@ -132,7 +132,17 @@ export default function AuditLogViewer() {
const formatTimestamp = (timestamp) => {
try {
return format(new Date(timestamp), "yyyy-MM-dd HH:mm:ss");
const date = new Date(timestamp);
// Format in Polish timezone
return date.toLocaleString("pl-PL", {
timeZone: "Europe/Warsaw",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
} catch {
return timestamp;
}

View File

@@ -31,14 +31,19 @@ export default function FinishDateWithHistory({ projectId, finishDate }) {
}, [projectId]);
const formatDateTime = (dateString) => {
const date = new Date(dateString);
return date.toLocaleDateString("pl-PL", {
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
});
try {
const date = new Date(dateString);
return date.toLocaleDateString("pl-PL", {
timeZone: "Europe/Warsaw",
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
});
} catch (error) {
return dateString;
}
};
const tooltipContent = (

View File

@@ -99,6 +99,7 @@ export async function logAuditEvent({
// Dynamic import to avoid Edge Runtime issues
const { default: db } = await import("./db.js");
// Use ISO format (UTC) - this is correctly handled by JavaScript Date parsing
const auditTimestamp = timestamp || new Date().toISOString();
const detailsJson = details ? JSON.stringify(details) : null;

View File

@@ -20,7 +20,7 @@ export function addNoteToProject(project_id, note, created_by = null, is_system
db.prepare(
`
INSERT INTO notes (project_id, note, created_by, is_system, note_date)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
VALUES (?, ?, ?, ?, datetime('now', 'localtime'))
`
).run(project_id, note, created_by, is_system ? 1 : 0);
}
@@ -49,7 +49,7 @@ export function addNoteToTask(
) {
db.prepare(
`INSERT INTO notes (task_id, note, is_system, created_by, note_date)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)`
VALUES (?, ?, ?, ?, datetime('now', 'localtime'))`
).run(task_id, note, is_system ? 1 : 0, created_by);
}

View File

@@ -77,7 +77,7 @@ export function createProject(data, userId = null) {
INSERT INTO projects (
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
wp, contact, notes, project_type, project_status, coordinates, created_by, assigned_to, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
const result = stmt.run(

View File

@@ -85,7 +85,7 @@ export function createProjectTask(data) {
project_id, task_template_id, custom_max_wait_days, status, priority,
created_by, assigned_to, created_at, updated_at
)
VALUES (?, ?, NULL, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
VALUES (?, ?, NULL, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
result = stmt.run(
data.project_id,
@@ -107,7 +107,7 @@ export function createProjectTask(data) {
project_id, custom_task_name, custom_max_wait_days, custom_description,
status, priority, created_by, assigned_to, created_at, updated_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
result = stmt.run(
data.project_id,
@@ -162,7 +162,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Starting a task - set date_started
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, date_started = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
SET status = ?, date_started = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -170,7 +170,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Completing a task - set date_completed
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, date_completed = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
SET status = ?, date_completed = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -178,7 +178,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Just updating status without changing timestamps
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, updated_at = CURRENT_TIMESTAMP
SET status = ?, updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -283,7 +283,7 @@ export function getProjectTasksByCreator(userId) {
export function updateProjectTaskAssignment(taskId, assignedToUserId) {
const stmt = db.prepare(`
UPDATE project_tasks
SET assigned_to = ?, updated_at = CURRENT_TIMESTAMP
SET assigned_to = ?, updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
return stmt.run(assignedToUserId, taskId);
@@ -335,9 +335,9 @@ export function updateProjectTask(taskId, updates, userId = null) {
// Handle status-specific timestamp updates
if (currentTask.status === "pending" && updates.status === "in_progress") {
fields.push("date_started = CURRENT_TIMESTAMP");
fields.push("date_started = datetime('now', 'localtime')");
} else if (updates.status === "completed") {
fields.push("date_completed = CURRENT_TIMESTAMP");
fields.push("date_completed = datetime('now', 'localtime')");
}
}
@@ -352,7 +352,7 @@ export function updateProjectTask(taskId, updates, userId = null) {
}
// Always update the updated_at timestamp
fields.push("updated_at = CURRENT_TIMESTAMP");
fields.push("updated_at = datetime('now', 'localtime')");
values.push(taskId);
const stmt = db.prepare(`

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;
}
};