From d48a11c9a23d40a8a48475aab8b2a9d6ab3761ba Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:25:16 +0800 Subject: [PATCH] Add support for formatting ISO dates --- src/_config/filters.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/_config/filters.js b/src/_config/filters.js index c9da407f..b44a21a7 100644 --- a/src/_config/filters.js +++ b/src/_config/filters.js @@ -12,8 +12,12 @@ export default function(eleventyConfig) { }); // Format dates - eleventyConfig.addFilter("formatDate", (dateObj) => { - return DateTime.fromJSDate(dateObj).toFormat("d LLLL yyyy"); + eleventyConfig.addFilter("formatDate", (date) => { + const dateFormat = "d LLLL yyyy"; + if (typeof date === "object") { + return DateTime.fromJSDate(date).toFormat(dateFormat); + } + return DateTime.fromISO(date, { setZone: true }).toFormat(dateFormat); }); // Limit number of items displayed