diff --git a/src/app/api/notes/route.js b/src/app/api/notes/route.js
index 048ac92..eb281c1 100644
--- a/src/app/api/notes/route.js
+++ b/src/app/api/notes/route.js
@@ -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);
diff --git a/src/app/projects/[id]/page.js b/src/app/projects/[id]/page.js
index 99967d8..76450aa 100644
--- a/src/app/projects/[id]/page.js
+++ b/src/app/projects/[id]/page.js
@@ -746,7 +746,7 @@ export default function ProjectViewPage() {
- {n.note_date}
+ {formatDate(n.note_date, { includeTime: true })}
{n.created_by_name && (
diff --git a/src/components/AuditLogViewer.js b/src/components/AuditLogViewer.js
index 9f6c04e..95b9eb9 100644
--- a/src/components/AuditLogViewer.js
+++ b/src/components/AuditLogViewer.js
@@ -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;
}
diff --git a/src/components/FinishDateWithHistory.js b/src/components/FinishDateWithHistory.js
index b71fee3..58bc018 100644
--- a/src/components/FinishDateWithHistory.js
+++ b/src/components/FinishDateWithHistory.js
@@ -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 = (
diff --git a/src/lib/auditLog.js b/src/lib/auditLog.js
index 00f32c6..74fddb1 100644
--- a/src/lib/auditLog.js
+++ b/src/lib/auditLog.js
@@ -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;
diff --git a/src/lib/queries/notes.js b/src/lib/queries/notes.js
index 903efa8..cb7d39c 100644
--- a/src/lib/queries/notes.js
+++ b/src/lib/queries/notes.js
@@ -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);
}
diff --git a/src/lib/queries/projects.js b/src/lib/queries/projects.js
index 7712df6..e3dcdde 100644
--- a/src/lib/queries/projects.js
+++ b/src/lib/queries/projects.js
@@ -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(
diff --git a/src/lib/queries/tasks.js b/src/lib/queries/tasks.js
index 7d2cecd..5aff732 100644
--- a/src/lib/queries/tasks.js
+++ b/src/lib/queries/tasks.js
@@ -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(`
diff --git a/src/lib/utils.js b/src/lib/utils.js
index f7ff393..7e9b632 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -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;
+ }
+};