Fix date timezone offset

post/wasm-gol-2
Ashelyn Dawn 1 year ago
parent 958edf7eec
commit ae3d0bcfd0

@ -26,7 +26,7 @@ export default async function Post({ params: { slug } }: { params: { slug: strin
return (
<>
<article className={styles.post}>
<span>{post.date.toLocaleDateString()}</span>
<span>{post.date.toLocaleDateString('en-US', { timeZone: 'UTC' })}</span>
<h1>{post.title}</h1>
<p className={styles.subtitle}>{post.subtitle}</p>

@ -28,7 +28,7 @@ export default async function Index() {
)}
<div className={styles.postLink}>
<h2><Link href={`/${post.slug}`}>{post.title}</Link></h2>
<span>{post.date.toLocaleDateString()}</span>
<span>{post.date.toLocaleDateString('en-US', { timeZone: 'UTC' })}</span>
<p>{post.subtitle}</p>
</div>
</>

@ -45,9 +45,12 @@ export async function loadSinglePage(slug: string): Promise<Post | null> {
if (!data.title) return null;
const [year, month, day] = postMatch.groups?.date.split('-') || []
const date = new Date(Date.UTC(parseInt(year), parseInt(month) - 1, parseInt(day)))
return {
slug: postMatch.groups?.slug || '',
date: new Date(postMatch.groups?.date || ''),
date,
title: data.title,
subtitle: data.subtitle,
unlisted: typeof data.unlisted === 'boolean' ? data.unlisted : false,

Loading…
Cancel
Save