feat: Update date handling to use local time formatting across various components and queries
This commit is contained in:
@@ -68,7 +68,7 @@ async function createNoteHandler(req) {
|
|||||||
.prepare(
|
.prepare(
|
||||||
`
|
`
|
||||||
INSERT INTO notes (project_id, task_id, note, created_by, note_date)
|
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);
|
.run(project_id || null, task_id || null, note, req.user?.id || null);
|
||||||
|
|||||||
@@ -746,7 +746,7 @@ export default function ProjectViewPage() {
|
|||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<span className="text-sm font-medium text-gray-500">
|
<span className="text-sm font-medium text-gray-500">
|
||||||
{n.note_date}
|
{formatDate(n.note_date, { includeTime: true })}
|
||||||
</span>
|
</span>
|
||||||
{n.created_by_name && (
|
{n.created_by_name && (
|
||||||
<span className="px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded-full font-medium">
|
<span className="px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded-full font-medium">
|
||||||
|
|||||||
@@ -132,7 +132,17 @@ export default function AuditLogViewer() {
|
|||||||
|
|
||||||
const formatTimestamp = (timestamp) => {
|
const formatTimestamp = (timestamp) => {
|
||||||
try {
|
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 {
|
} catch {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,19 @@ export default function FinishDateWithHistory({ projectId, finishDate }) {
|
|||||||
}, [projectId]);
|
}, [projectId]);
|
||||||
|
|
||||||
const formatDateTime = (dateString) => {
|
const formatDateTime = (dateString) => {
|
||||||
const date = new Date(dateString);
|
try {
|
||||||
return date.toLocaleDateString("pl-PL", {
|
const date = new Date(dateString);
|
||||||
year: "numeric",
|
return date.toLocaleDateString("pl-PL", {
|
||||||
month: "short",
|
timeZone: "Europe/Warsaw",
|
||||||
day: "numeric",
|
year: "numeric",
|
||||||
hour: "2-digit",
|
month: "short",
|
||||||
minute: "2-digit",
|
day: "numeric",
|
||||||
});
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const tooltipContent = (
|
const tooltipContent = (
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ export async function logAuditEvent({
|
|||||||
// Dynamic import to avoid Edge Runtime issues
|
// Dynamic import to avoid Edge Runtime issues
|
||||||
const { default: db } = await import("./db.js");
|
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 auditTimestamp = timestamp || new Date().toISOString();
|
||||||
const detailsJson = details ? JSON.stringify(details) : null;
|
const detailsJson = details ? JSON.stringify(details) : null;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function addNoteToProject(project_id, note, created_by = null, is_system
|
|||||||
db.prepare(
|
db.prepare(
|
||||||
`
|
`
|
||||||
INSERT INTO notes (project_id, note, created_by, is_system, note_date)
|
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);
|
).run(project_id, note, created_by, is_system ? 1 : 0);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ export function addNoteToTask(
|
|||||||
) {
|
) {
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`INSERT INTO notes (task_id, note, is_system, created_by, note_date)
|
`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);
|
).run(task_id, note, is_system ? 1 : 0, created_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function createProject(data, userId = null) {
|
|||||||
INSERT INTO projects (
|
INSERT INTO projects (
|
||||||
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
|
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
|
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(
|
const result = stmt.run(
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export function createProjectTask(data) {
|
|||||||
project_id, task_template_id, custom_max_wait_days, status, priority,
|
project_id, task_template_id, custom_max_wait_days, status, priority,
|
||||||
created_by, assigned_to, created_at, updated_at
|
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(
|
result = stmt.run(
|
||||||
data.project_id,
|
data.project_id,
|
||||||
@@ -107,7 +107,7 @@ export function createProjectTask(data) {
|
|||||||
project_id, custom_task_name, custom_max_wait_days, custom_description,
|
project_id, custom_task_name, custom_max_wait_days, custom_description,
|
||||||
status, priority, created_by, assigned_to, created_at, updated_at
|
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(
|
result = stmt.run(
|
||||||
data.project_id,
|
data.project_id,
|
||||||
@@ -162,7 +162,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
|
|||||||
// Starting a task - set date_started
|
// Starting a task - set date_started
|
||||||
stmt = db.prepare(`
|
stmt = db.prepare(`
|
||||||
UPDATE project_tasks
|
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 = ?
|
WHERE id = ?
|
||||||
`);
|
`);
|
||||||
result = stmt.run(status, taskId);
|
result = stmt.run(status, taskId);
|
||||||
@@ -170,7 +170,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
|
|||||||
// Completing a task - set date_completed
|
// Completing a task - set date_completed
|
||||||
stmt = db.prepare(`
|
stmt = db.prepare(`
|
||||||
UPDATE project_tasks
|
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 = ?
|
WHERE id = ?
|
||||||
`);
|
`);
|
||||||
result = stmt.run(status, taskId);
|
result = stmt.run(status, taskId);
|
||||||
@@ -178,7 +178,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
|
|||||||
// Just updating status without changing timestamps
|
// Just updating status without changing timestamps
|
||||||
stmt = db.prepare(`
|
stmt = db.prepare(`
|
||||||
UPDATE project_tasks
|
UPDATE project_tasks
|
||||||
SET status = ?, updated_at = CURRENT_TIMESTAMP
|
SET status = ?, updated_at = datetime('now', 'localtime')
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`);
|
`);
|
||||||
result = stmt.run(status, taskId);
|
result = stmt.run(status, taskId);
|
||||||
@@ -283,7 +283,7 @@ export function getProjectTasksByCreator(userId) {
|
|||||||
export function updateProjectTaskAssignment(taskId, assignedToUserId) {
|
export function updateProjectTaskAssignment(taskId, assignedToUserId) {
|
||||||
const stmt = db.prepare(`
|
const stmt = db.prepare(`
|
||||||
UPDATE project_tasks
|
UPDATE project_tasks
|
||||||
SET assigned_to = ?, updated_at = CURRENT_TIMESTAMP
|
SET assigned_to = ?, updated_at = datetime('now', 'localtime')
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`);
|
`);
|
||||||
return stmt.run(assignedToUserId, taskId);
|
return stmt.run(assignedToUserId, taskId);
|
||||||
@@ -335,9 +335,9 @@ export function updateProjectTask(taskId, updates, userId = null) {
|
|||||||
|
|
||||||
// Handle status-specific timestamp updates
|
// Handle status-specific timestamp updates
|
||||||
if (currentTask.status === "pending" && updates.status === "in_progress") {
|
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") {
|
} 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
|
// Always update the updated_at timestamp
|
||||||
fields.push("updated_at = CURRENT_TIMESTAMP");
|
fields.push("updated_at = datetime('now', 'localtime')");
|
||||||
values.push(taskId);
|
values.push(taskId);
|
||||||
|
|
||||||
const stmt = db.prepare(`
|
const stmt = db.prepare(`
|
||||||
|
|||||||
@@ -51,14 +51,17 @@ export const formatDate = (date, options = {}) => {
|
|||||||
return "Nieprawidłowa data";
|
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
|
// Default to DD.MM.YYYY format
|
||||||
const day = String(dateObj.getDate()).padStart(2, "0");
|
const day = String(polandTime.getDate()).padStart(2, "0");
|
||||||
const month = String(dateObj.getMonth() + 1).padStart(2, "0");
|
const month = String(polandTime.getMonth() + 1).padStart(2, "0");
|
||||||
const year = dateObj.getFullYear();
|
const year = polandTime.getFullYear();
|
||||||
|
|
||||||
if (options.includeTime) {
|
if (options.includeTime) {
|
||||||
const hours = String(dateObj.getHours()).padStart(2, "0");
|
const hours = String(polandTime.getHours()).padStart(2, "0");
|
||||||
const minutes = String(dateObj.getMinutes()).padStart(2, "0");
|
const minutes = String(polandTime.getMinutes()).padStart(2, "0");
|
||||||
return `${day}.${month}.${year} ${hours}:${minutes}`;
|
return `${day}.${month}.${year} ${hours}:${minutes}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,3 +132,27 @@ export const formatCoordinates = (coordinatesString) => {
|
|||||||
return 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user