1
0

Fix date calculation in Task: Postpone command (#406)

* Fix date calculation in `Task: Postpone` command

Create new postponed date as a "naive" date to prevent it from being
converted to UTC.

* Convert types to satisfy deno linter

---------

Co-authored-by: Bob Gibson <rjg@rjgibson.org>
This commit is contained in:
rjgibson 2023-05-22 05:54:25 -04:00 committed by GitHub
parent 9b49317bbf
commit b256269897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,7 +180,11 @@ export async function postponeCommand() {
if (!option) {
return;
}
const d = new Date(date);
// Parse "naive" due date
let [yyyy, mm, dd] = date.split("-").map(Number)
// Create new naive Date object.
// `monthIndex` parameter is zero-based, so subtract 1 from parsed month.
const d = new Date(yyyy, mm - 1, dd);
switch (option.name) {
case "a day":
d.setDate(d.getDate() + 1);
@ -192,6 +196,7 @@ export async function postponeCommand() {
d.setDate(d.getDate() + ((7 - d.getDay() + 1) % 7 || 7));
break;
}
// console.log("New date", niceDate(d));
await editor.dispatch({
changes: {
from: node.from,