From c78f77b592bd7ca2d769330764b64cb0378f89ed Mon Sep 17 00:00:00 2001 From: Linus Rachlis Date: Sun, 24 Nov 2024 10:56:10 -0500 Subject: [PATCH] fix: timezone issue with ISO dates If the date is in YYYY-MM-DD format, which is the default for the Obsidian 'date' file property, it will be interpreted as UTC midnight which will mean it renders incorrectly as the previous day when passed to 'getLocaleDateString'. Adding a time makes it interpret as midnight in the local timezone instead so it will render as expected. --- quartz/plugins/transformers/lastmod.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/quartz/plugins/transformers/lastmod.ts b/quartz/plugins/transformers/lastmod.ts index fe8c01bcf..18bfd583a 100644 --- a/quartz/plugins/transformers/lastmod.ts +++ b/quartz/plugins/transformers/lastmod.ts @@ -48,7 +48,15 @@ export const CreatedModifiedDate: QuartzTransformerPlugin> = (u created ||= st.birthtimeMs modified ||= st.mtimeMs } else if (source === "frontmatter" && file.data.frontmatter) { - created ||= file.data.frontmatter.date as MaybeDate + if (!created) { + created = file.data.frontmatter.date as MaybeDate + if (typeof created === "string" && /^\d{4}-\d{2}-\d{2}$/.test(created)) { + // If the date is in YYYY-MM-DD format, it will be interpreted as UTC midnight + // which will mean it renders incorrectly as the previous day. Adding a time + // makes it interpret as the local timezone instead so it will render correctly. + created += " 00:00" + } + } modified ||= file.data.frontmatter.lastmod as MaybeDate modified ||= file.data.frontmatter.updated as MaybeDate modified ||= file.data.frontmatter["last-modified"] as MaybeDate