From 18d99cfe6c34c313103d637002d76324eee309d4 Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:21:32 +0800 Subject: [PATCH] Use luxon to format dates --- src/_config/filters.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/_config/filters.js b/src/_config/filters.js index b0258515..c9da407f 100644 --- a/src/_config/filters.js +++ b/src/_config/filters.js @@ -1,3 +1,5 @@ +import { DateTime } from "luxon"; + export default function(eleventyConfig) { // Filter contents by category eleventyConfig.addFilter("filterByCategory", function(contents, cat) { @@ -10,14 +12,8 @@ export default function(eleventyConfig) { }); // Format dates - const dateOptions = { - year: 'numeric', - month: 'long', - day: 'numeric', - }; - const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions); - eleventyConfig.addFilter("formatDate", function(date) { - return dateTimeLocale.format(date); + eleventyConfig.addFilter("formatDate", (dateObj) => { + return DateTime.fromJSDate(dateObj).toFormat("d LLLL yyyy"); }); // Limit number of items displayed