Disable date-fns-tz timezone offset solution, add thoughts, revert

This commit is contained in:
2023-11-28 04:16:31 -06:00
parent 51369a9935
commit 3285d9f6d9

View File

@@ -1,6 +1,6 @@
import { z, defineCollection } from "astro:content";
import { parse } from "date-fns";
import { zonedTimeToUtc } from "date-fns-tz";
// import { zonedTimeToUtc } from "date-fns-tz";
const blogCollection = defineCollection({
type: "content", // v2.5.0 and later
@@ -8,10 +8,13 @@ const blogCollection = defineCollection({
title: z.string(),
description: z.string(),
pubDate: z.string().transform((date) => {
// I am truly lost on how TZ works in Javascript Dates.
// I believe somehow the solution would lie here in making sure that the date offset is parsed and transmitted properly,
// but there is no insight in how this works so far. I'm lost as fuck.
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const parsed = parse(date, "yyyy-MM-dd HH:mm:ss XX", new Date());
const utc = zonedTimeToUtc(parsed, timezone);
return z.date().parse(utc);
// const utc = zonedTimeToUtc(parsed, timezone);
return z.date().parse(parsed);
}),
tags: z.array(z.string()),
preview_image: z.string().optional(),