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 ( return (
<> <>
<article className={styles.post}> <article className={styles.post}>
<span>{post.date.toLocaleDateString()}</span> <span>{post.date.toLocaleDateString('en-US', { timeZone: 'UTC' })}</span>
<h1>{post.title}</h1> <h1>{post.title}</h1>
<p className={styles.subtitle}>{post.subtitle}</p> <p className={styles.subtitle}>{post.subtitle}</p>

@ -28,7 +28,7 @@ export default async function Index() {
)} )}
<div className={styles.postLink}> <div className={styles.postLink}>
<h2><Link href={`/${post.slug}`}>{post.title}</Link></h2> <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> <p>{post.subtitle}</p>
</div> </div>
</> </>

@ -45,9 +45,12 @@ export async function loadSinglePage(slug: string): Promise<Post | null> {
if (!data.title) return 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 { return {
slug: postMatch.groups?.slug || '', slug: postMatch.groups?.slug || '',
date: new Date(postMatch.groups?.date || ''), date,
title: data.title, title: data.title,
subtitle: data.subtitle, subtitle: data.subtitle,
unlisted: typeof data.unlisted === 'boolean' ? data.unlisted : false, unlisted: typeof data.unlisted === 'boolean' ? data.unlisted : false,

Loading…
Cancel
Save