Skip to content

fix: use local date getters instead of toISOString() to prevent timez…#1466

Open
shabnam311 wants to merge 2 commits into
aryandas2911:mainfrom
shabnam311:fix/duedate-timezone-parsing-mismatch
Open

fix: use local date getters instead of toISOString() to prevent timez…#1466
shabnam311 wants to merge 2 commits into
aryandas2911:mainfrom
shabnam311:fix/duedate-timezone-parsing-mismatch

Conversation

@shabnam311

Copy link
Copy Markdown
Contributor

Description

Fixes #1395

Problem

In TaskFormModal.jsx, when editing an existing task, the useEffect hook extracts the date and time from task.dueDate using two inconsistent methods:

const datePart = dt.toISOString().slice(0, 10); // ← UTC
const timePart = dt.toTimeString().slice(0, 5); // ← Local time
toISOString() converts to UTC, which shifts the date backward for users in UTC+ timezones (e.g., IST = UTC+5:30)
toTimeString() uses local time
This mismatch means that a task due on 2026-06-08T02:00:00+05:30 gets its date extracted as 2026-06-07 (UTC) but its time as 02:00 (local). When the user saves without changing anything, the reconstructed datetime 2026-06-07T02:00:00 is a full 24 hours earlier than the original.

Fix
Replaced dt.toISOString().slice(0, 10) with local date getters (getFullYear(), getMonth(), getDate()) to ensure both the date and time parts are extracted in the same timezone (local):

const yyyy = dt.getFullYear();
const mm = String(dt.getMonth() + 1).padStart(2, "0");
const dd = String(dt.getDate()).padStart(2, "0");
const datePart = `${yyyy}-${mm}-${dd}`; // Local time
const timePart = dt.toTimeString().slice(0, 5); // Local time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Date/Time parsing mismatch in TaskFormModal shifts tasks backward by 24 hours every time they are edited in UTC+ timezones

1 participant