Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/components/task-edit/MetadataEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,28 @@ export class TaskMetadataEditor extends Component {
});

if (value) {
// Date format conversion (should match date format used in the plugin)
// Date format conversion using UTC to avoid timezone issues
try {
const date = new Date(value);
const formattedDate = date.toISOString().split("T")[0];
dateInput.value = formattedDate;
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
const day = String(date.getUTCDate()).padStart(2, "0");
dateInput.value = `${year}-${month}-${day}`;
} catch (e) {
console.error(`Cannot parse date: ${value}`, e);
}
}

this.registerDomEvent(dateInput, "change", () => {
this.notifyMetadataChange(field, dateInput.value);
const dateValue = dateInput.value;
if (dateValue) {
// Create date at noon UTC to avoid timezone edge cases
const [year, month, day] = dateValue.split("-").map(Number);
const timestamp = new Date(Date.UTC(year, month - 1, day, 12, 0, 0)).getTime();
this.notifyMetadataChange(field, timestamp);
} else {
this.notifyMetadataChange(field, undefined);
}
});
}

Expand Down
56 changes: 25 additions & 31 deletions src/components/task-view/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,13 @@ export class TaskDetailsComponent extends Component {
cls: "date-input",
});
if (task.metadata.dueDate) {
// Use local date to avoid timezone issues
// Use UTC methods to avoid timezone issues
const date = new Date(task.metadata.dueDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
const day = String(date.getUTCDate()).padStart(2, "0");
dueDateInput.value = `${year}-${month}-${day}`;
}

// Start date
} // Start date
const startDateField = this.createFormField(
this.editFormEl,
t("Start Date")
Expand All @@ -453,11 +451,11 @@ export class TaskDetailsComponent extends Component {
cls: "date-input",
});
if (task.metadata.startDate) {
// Use local date to avoid timezone issues
// Use UTC methods to avoid timezone issues
const date = new Date(task.metadata.startDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
const day = String(date.getUTCDate()).padStart(2, "0");
startDateInput.value = `${year}-${month}-${day}`;
}

Expand All @@ -471,11 +469,11 @@ export class TaskDetailsComponent extends Component {
cls: "date-input",
});
if (task.metadata.scheduledDate) {
// Use local date to avoid timezone issues
// Use UTC methods to avoid timezone issues
const date = new Date(task.metadata.scheduledDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
const day = String(date.getUTCDate()).padStart(2, "0");
scheduledDateInput.value = `${year}-${month}-${day}`;
}

Expand All @@ -489,11 +487,11 @@ export class TaskDetailsComponent extends Component {
cls: "date-input",
});
if (task.metadata.cancelledDate) {
// Use local date to avoid timezone issues
// Use UTC methods to avoid timezone issues
const date = new Date(task.metadata.cancelledDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
const day = String(date.getUTCDate()).padStart(2, "0");
cancelledDateInput.value = `${year}-${month}-${day}`;
}

Expand Down Expand Up @@ -550,9 +548,9 @@ export class TaskDetailsComponent extends Component {
// Parse dates and check if they've changed
const dueDateValue = dueDateInput.value;
if (dueDateValue) {
// Create date in local timezone to avoid timezone offset issues
// Create date at noon UTC to avoid timezone edge cases
const [year, month, day] = dueDateValue.split("-").map(Number);
const newDueDate = new Date(year, month - 1, day).getTime();
const newDueDate = new Date(Date.UTC(year, month - 1, day, 12, 0, 0)).getTime();
// Only update if the date has changed or is different from the original
if (task.metadata.dueDate !== newDueDate) {
metadata.dueDate = newDueDate;
Expand All @@ -569,11 +567,11 @@ export class TaskDetailsComponent extends Component {

const startDateValue = startDateInput.value;
if (startDateValue) {
// Create date in local timezone to avoid timezone offset issues
// Create date at noon UTC to avoid timezone edge cases
const [year, month, day] = startDateValue
.split("-")
.map(Number);
const newStartDate = new Date(year, month - 1, day).getTime();
const newStartDate = new Date(Date.UTC(year, month - 1, day, 12, 0, 0)).getTime();
// Only update if the date has changed or is different from the original
if (task.metadata.startDate !== newStartDate) {
metadata.startDate = newStartDate;
Expand All @@ -590,14 +588,12 @@ export class TaskDetailsComponent extends Component {

const scheduledDateValue = scheduledDateInput.value;
if (scheduledDateValue) {
// Create date in local timezone to avoid timezone offset issues
// Create date at noon UTC to avoid timezone edge cases
const [year, month, day] = scheduledDateValue
.split("-")
.map(Number);
const newScheduledDate = new Date(
year,
month - 1,
day
Date.UTC(year, month - 1, day, 12, 0, 0)
).getTime();
// Only update if the date has changed or is different from the original
if (task.metadata.scheduledDate !== newScheduledDate) {
Expand All @@ -615,14 +611,12 @@ export class TaskDetailsComponent extends Component {

const cancelledDateValue = cancelledDateInput.value;
if (cancelledDateValue) {
// Create date in local timezone to avoid timezone offset issues
// Create date at noon UTC to avoid timezone edge cases
const [year, month, day] = cancelledDateValue
.split("-")
.map(Number);
const newCancelledDate = new Date(
year,
month - 1,
day
Date.UTC(year, month - 1, day, 12, 0, 0)
).getTime();
// Only update if the date has changed or is different from the original
if (task.metadata.cancelledDate !== newCancelledDate) {
Expand Down