From 79417933df2012930448ebb115e2ad6ebd94abb7 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sat, 16 Nov 2024 09:35:03 -0800 Subject: [PATCH] fix: dates --- config/filters/dates.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/config/filters/dates.js b/config/filters/dates.js index 5ef3c07c..e492ceff 100644 --- a/config/filters/dates.js +++ b/config/filters/dates.js @@ -1,26 +1,14 @@ +import { DateTime } from "luxon"; + export default { stringToRFC822Date: (dateString) => { - const date = new Date(dateString); + const date = DateTime.fromISO(dateString, { zone: "America/Los_Angeles" }); - if (isNaN(date)) return ""; - - const options = { - weekday: "short", - day: "2-digit", - month: "short", - year: "numeric", - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - timeZoneName: "short", - }; - const formatter = new Intl.DateTimeFormat("en-GB", options); - - return formatter.format(date).replace(",", ""); + return date.isValid ? date.toRFC2822() : ""; }, stringToRFC3339: (dateString) => { - const date = new Date(dateString); + const date = DateTime.fromISO(dateString, { zone: "America/Los_Angeles" }); - return isNaN(date) ? "" : date.toISOString(); + return date.isValid ? date.toISO() : ""; }, };