Skip to content

Resolve date discrepancy and remove tinytime dependency #1812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"simple-functional-loader": "^1.2.1",
"stringify-object": "^3.3.0",
"tailwindcss": "^3.4.3",
"tinytime": "^0.2.6",
"unified": "^10.1.2",
"unist-util-filter": "^4.0.1",
"unist-util-visit": "^4.1.2",
Expand Down
8 changes: 7 additions & 1 deletion src/components/PostItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import clsx from 'clsx'
import { Button } from '@/components/Button'
import { formatDate } from '@/utils/formatDate'

const dateFormat = {
month: 'long',
day: 'numeric',
year: 'numeric',
}

export default function PostItem({ title, category, slug, date, children, wide = false }) {
return (
<article
Expand Down Expand Up @@ -31,7 +37,7 @@ export default function PostItem({ title, category, slug, date, children, wide =
'lg:absolute lg:top-0 lg:right-full lg:mr-8 lg:whitespace-nowrap': wide,
})}
>
<time dateTime={date}>{formatDate(date, '{MMMM} {DD}, {YYYY}')}</time>
<time dateTime={date}>{formatDate(date, dateFormat)}</time>
</dd>
</dl>
<svg
Expand Down
9 changes: 8 additions & 1 deletion src/layouts/BlogPostLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { MDXProvider } from '@mdx-js/react'
import clsx from 'clsx'
import Link from 'next/link'

const dateFormat = {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric',
}

export function BlogPostLayout({ children, meta }) {
return (
<div className="overflow-hidden">
Expand Down Expand Up @@ -50,7 +57,7 @@ export function BlogPostLayout({ children, meta }) {
className={clsx('absolute top-0 inset-x-0 text-slate-700 dark:text-slate-400')}
>
<time dateTime={meta.date}>
{formatDate(meta.date, '{dddd}, {MMMM} {DD}, {YYYY}')}
{formatDate(meta.date, dateFormat)}
</time>
</dd>
</dl>
Expand Down
10 changes: 9 additions & 1 deletion src/layouts/JobPostingLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { mdxComponents } from '@/utils/mdxComponents'
import { MDXProvider } from '@mdx-js/react'
import Link from 'next/link'

const dateFormat = {
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
year: 'numeric'
}

function BackgroundBeams() {
return (
<div className="pointer-events-none absolute inset-x-0 top-0 flex justify-center overflow-hidden">
Expand Down Expand Up @@ -203,7 +211,7 @@ export function JobPostingLayout({ children, meta }) {
<p className="mt-7 text-sm/7 text-slate-500">
Closes on{' '}
<time dateTime={meta.dateCloses}>
{formatDate(meta.dateCloses, '{MMMM} {Do} at {h}:{mm}{a} ET')}
{formatDate(meta.dateCloses, dateFormat)}
</time>
</p>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { formatDate } from '@/utils/formatDate'
import buildRss from '@/scripts/build-rss'
import { renderToStaticMarkup } from 'react-dom/server'

const dateFormat = {
month: 'long',
day: 'numeric',
year: 'numeric',
}

export default function Blog({ posts }) {
return (
<main className="max-w-[52rem] mx-auto px-4 pb-28 sm:px-6 md:px-8 xl:px-12 lg:max-w-6xl">
Expand Down Expand Up @@ -52,7 +58,7 @@ export default function Blog({ posts }) {
<dl className="absolute left-0 top-0 lg:left-auto lg:right-full lg:mr-[calc(6.5rem+1px)]">
<dt className="sr-only">Date</dt>
<dd className={clsx('whitespace-nowrap text-sm leading-6 dark:text-slate-400')}>
<time dateTime={meta.date}>{formatDate(meta.date, '{MMMM} {DD}, {YYYY}')}</time>
<time dateTime={meta.date}>{formatDate(meta.date, dateFormat)}</time>
</dd>
</dl>
</div>
Expand Down
17 changes: 12 additions & 5 deletions src/utils/formatDate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import tinytime from 'tinytime'
export function formatDate(dateString, options) {
const date = new Date(dateString);
const defaultTimeZoneOptions = options?.hour
? {
timeZoneName: 'shortGeneric',
timeZone: 'America/New_York',
}
: {};

export function formatDate(date, format) {
return tinytime(format)
.render(typeof date === 'string' ? new Date(date) : date)
.replace('Febuary', 'February')
return new Intl.DateTimeFormat("en-US", {
...defaultTimeZoneOptions,
...options,
}).format(date);
}