Skip to content

Commit 1e8f404

Browse files
authored
Merge pull request #361 from fastrick/master
Fix: task gutter select date
2 parents ac1f6ec + 9e9af7f commit 1e8f404

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/components/task-edit/MetadataEditor.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,28 @@ export class TaskMetadataEditor extends Component {
337337
});
338338

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

350352
this.registerDomEvent(dateInput, "change", () => {
351-
this.notifyMetadataChange(field, dateInput.value);
353+
const dateValue = dateInput.value;
354+
if (dateValue) {
355+
// Create date at noon UTC to avoid timezone edge cases
356+
const [year, month, day] = dateValue.split("-").map(Number);
357+
const timestamp = new Date(Date.UTC(year, month - 1, day, 12, 0, 0)).getTime();
358+
this.notifyMetadataChange(field, timestamp);
359+
} else {
360+
this.notifyMetadataChange(field, undefined);
361+
}
352362
});
353363
}
354364

src/components/task-view/details.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,13 @@ export class TaskDetailsComponent extends Component {
435435
cls: "date-input",
436436
});
437437
if (task.metadata.dueDate) {
438-
// Use local date to avoid timezone issues
438+
// Use UTC methods to avoid timezone issues
439439
const date = new Date(task.metadata.dueDate);
440-
const year = date.getFullYear();
441-
const month = String(date.getMonth() + 1).padStart(2, "0");
442-
const day = String(date.getDate()).padStart(2, "0");
440+
const year = date.getUTCFullYear();
441+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
442+
const day = String(date.getUTCDate()).padStart(2, "0");
443443
dueDateInput.value = `${year}-${month}-${day}`;
444-
}
445-
446-
// Start date
444+
} // Start date
447445
const startDateField = this.createFormField(
448446
this.editFormEl,
449447
t("Start Date")
@@ -453,11 +451,11 @@ export class TaskDetailsComponent extends Component {
453451
cls: "date-input",
454452
});
455453
if (task.metadata.startDate) {
456-
// Use local date to avoid timezone issues
454+
// Use UTC methods to avoid timezone issues
457455
const date = new Date(task.metadata.startDate);
458-
const year = date.getFullYear();
459-
const month = String(date.getMonth() + 1).padStart(2, "0");
460-
const day = String(date.getDate()).padStart(2, "0");
456+
const year = date.getUTCFullYear();
457+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
458+
const day = String(date.getUTCDate()).padStart(2, "0");
461459
startDateInput.value = `${year}-${month}-${day}`;
462460
}
463461

@@ -471,11 +469,11 @@ export class TaskDetailsComponent extends Component {
471469
cls: "date-input",
472470
});
473471
if (task.metadata.scheduledDate) {
474-
// Use local date to avoid timezone issues
472+
// Use UTC methods to avoid timezone issues
475473
const date = new Date(task.metadata.scheduledDate);
476-
const year = date.getFullYear();
477-
const month = String(date.getMonth() + 1).padStart(2, "0");
478-
const day = String(date.getDate()).padStart(2, "0");
474+
const year = date.getUTCFullYear();
475+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
476+
const day = String(date.getUTCDate()).padStart(2, "0");
479477
scheduledDateInput.value = `${year}-${month}-${day}`;
480478
}
481479

@@ -489,11 +487,11 @@ export class TaskDetailsComponent extends Component {
489487
cls: "date-input",
490488
});
491489
if (task.metadata.cancelledDate) {
492-
// Use local date to avoid timezone issues
490+
// Use UTC methods to avoid timezone issues
493491
const date = new Date(task.metadata.cancelledDate);
494-
const year = date.getFullYear();
495-
const month = String(date.getMonth() + 1).padStart(2, "0");
496-
const day = String(date.getDate()).padStart(2, "0");
492+
const year = date.getUTCFullYear();
493+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
494+
const day = String(date.getUTCDate()).padStart(2, "0");
497495
cancelledDateInput.value = `${year}-${month}-${day}`;
498496
}
499497

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

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

591589
const scheduledDateValue = scheduledDateInput.value;
592590
if (scheduledDateValue) {
593-
// Create date in local timezone to avoid timezone offset issues
591+
// Create date at noon UTC to avoid timezone edge cases
594592
const [year, month, day] = scheduledDateValue
595593
.split("-")
596594
.map(Number);
597595
const newScheduledDate = new Date(
598-
year,
599-
month - 1,
600-
day
596+
Date.UTC(year, month - 1, day, 12, 0, 0)
601597
).getTime();
602598
// Only update if the date has changed or is different from the original
603599
if (task.metadata.scheduledDate !== newScheduledDate) {
@@ -615,14 +611,12 @@ export class TaskDetailsComponent extends Component {
615611

616612
const cancelledDateValue = cancelledDateInput.value;
617613
if (cancelledDateValue) {
618-
// Create date in local timezone to avoid timezone offset issues
614+
// Create date at noon UTC to avoid timezone edge cases
619615
const [year, month, day] = cancelledDateValue
620616
.split("-")
621617
.map(Number);
622618
const newCancelledDate = new Date(
623-
year,
624-
month - 1,
625-
day
619+
Date.UTC(year, month - 1, day, 12, 0, 0)
626620
).getTime();
627621
// Only update if the date has changed or is different from the original
628622
if (task.metadata.cancelledDate !== newCancelledDate) {

0 commit comments

Comments
 (0)