From b91a55cb64ef8e9466cdccbc116449ed69b7a6ba Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Fri, 7 Oct 2022 00:04:12 +0200 Subject: [PATCH] Ensure dates consider timezones --- packages/plugs/core/dates.ts | 10 +++++++++- packages/plugs/core/template.ts | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/plugs/core/dates.ts b/packages/plugs/core/dates.ts index dea50907..c3e23097 100644 --- a/packages/plugs/core/dates.ts +++ b/packages/plugs/core/dates.ts @@ -1,3 +1,11 @@ export function niceDate(d: Date): string { - return d.toISOString().split("T")[0]; + function pad(n: number) { + let s = String(n); + if (s.length === 1) { + s = '0' + s; + } + return s; + } + + return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) } diff --git a/packages/plugs/core/template.ts b/packages/plugs/core/template.ts index fcefa614..e23a7216 100644 --- a/packages/plugs/core/template.ts +++ b/packages/plugs/core/template.ts @@ -143,8 +143,7 @@ export async function dailyNoteCommand() { } catch { console.warn(`No daily note template found at ${dailyNoteTemplate}`); } - let isoDate = new Date().toISOString(); - let date = isoDate.split("T")[0]; + let date = niceDate(new Date()) let pageName = `${dailyNotePrefix}${date}`; if (dailyNoteTemplateText) { try {