Skip to content

Commit e8c2627

Browse files
Resolve date discrepancy and remove tinytime dependency (#1812)
* Resolve time discrepancy and remove need for 3rd-party package tinytime * Remove unused `DateTimeFormats` * Resolve DateTimeFormat for blog post dates
1 parent 2da9acb commit e8c2627

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"simple-functional-loader": "^1.2.1",
6262
"stringify-object": "^3.3.0",
6363
"tailwindcss": "^3.4.3",
64-
"tinytime": "^0.2.6",
6564
"unified": "^10.1.2",
6665
"unist-util-filter": "^4.0.1",
6766
"unist-util-visit": "^4.1.2",

src/components/PostItem.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import clsx from 'clsx'
33
import { Button } from '@/components/Button'
44
import { formatDate } from '@/utils/formatDate'
55

6+
const dateFormat = {
7+
month: 'long',
8+
day: 'numeric',
9+
year: 'numeric',
10+
}
11+
612
export default function PostItem({ title, category, slug, date, children, wide = false }) {
713
return (
814
<article
@@ -31,7 +37,7 @@ export default function PostItem({ title, category, slug, date, children, wide =
3137
'lg:absolute lg:top-0 lg:right-full lg:mr-8 lg:whitespace-nowrap': wide,
3238
})}
3339
>
34-
<time dateTime={date}>{formatDate(date, '{MMMM} {DD}, {YYYY}')}</time>
40+
<time dateTime={date}>{formatDate(date, dateFormat)}</time>
3541
</dd>
3642
</dl>
3743
<svg

src/layouts/BlogPostLayout.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { MDXProvider } from '@mdx-js/react'
66
import clsx from 'clsx'
77
import Link from 'next/link'
88

9+
const dateFormat = {
10+
weekday: 'long',
11+
month: 'long',
12+
day: 'numeric',
13+
year: 'numeric',
14+
}
15+
916
export function BlogPostLayout({ children, meta }) {
1017
return (
1118
<div className="overflow-hidden">
@@ -50,7 +57,7 @@ export function BlogPostLayout({ children, meta }) {
5057
className={clsx('absolute top-0 inset-x-0 text-slate-700 dark:text-slate-400')}
5158
>
5259
<time dateTime={meta.date}>
53-
{formatDate(meta.date, '{dddd}, {MMMM} {DD}, {YYYY}')}
60+
{formatDate(meta.date, dateFormat)}
5461
</time>
5562
</dd>
5663
</dl>

src/layouts/JobPostingLayout.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import { mdxComponents } from '@/utils/mdxComponents'
77
import { MDXProvider } from '@mdx-js/react'
88
import Link from 'next/link'
99

10+
const dateFormat = {
11+
month: 'long',
12+
day: 'numeric',
13+
hour: 'numeric',
14+
minute: 'numeric',
15+
year: 'numeric'
16+
}
17+
1018
function BackgroundBeams() {
1119
return (
1220
<div className="pointer-events-none absolute inset-x-0 top-0 flex justify-center overflow-hidden">
@@ -203,7 +211,7 @@ export function JobPostingLayout({ children, meta }) {
203211
<p className="mt-7 text-sm/7 text-slate-500">
204212
Closes on{' '}
205213
<time dateTime={meta.dateCloses}>
206-
{formatDate(meta.dateCloses, '{MMMM} {Do} at {h}:{mm}{a} ET')}
214+
{formatDate(meta.dateCloses, dateFormat)}
207215
</time>
208216
</p>
209217
</div>

src/pages/blog/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { formatDate } from '@/utils/formatDate'
77
import buildRss from '@/scripts/build-rss'
88
import { renderToStaticMarkup } from 'react-dom/server'
99

10+
const dateFormat = {
11+
month: 'long',
12+
day: 'numeric',
13+
year: 'numeric',
14+
}
15+
1016
export default function Blog({ posts }) {
1117
return (
1218
<main className="max-w-[52rem] mx-auto px-4 pb-28 sm:px-6 md:px-8 xl:px-12 lg:max-w-6xl">
@@ -52,7 +58,7 @@ export default function Blog({ posts }) {
5258
<dl className="absolute left-0 top-0 lg:left-auto lg:right-full lg:mr-[calc(6.5rem+1px)]">
5359
<dt className="sr-only">Date</dt>
5460
<dd className={clsx('whitespace-nowrap text-sm leading-6 dark:text-slate-400')}>
55-
<time dateTime={meta.date}>{formatDate(meta.date, '{MMMM} {DD}, {YYYY}')}</time>
61+
<time dateTime={meta.date}>{formatDate(meta.date, dateFormat)}</time>
5662
</dd>
5763
</dl>
5864
</div>

src/utils/formatDate.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import tinytime from 'tinytime'
1+
export function formatDate(dateString, options) {
2+
const date = new Date(dateString);
3+
const defaultTimeZoneOptions = options?.hour
4+
? {
5+
timeZoneName: 'shortGeneric',
6+
timeZone: 'America/New_York',
7+
}
8+
: {};
29

3-
export function formatDate(date, format) {
4-
return tinytime(format)
5-
.render(typeof date === 'string' ? new Date(date) : date)
6-
.replace('Febuary', 'February')
10+
return new Intl.DateTimeFormat("en-US", {
11+
...defaultTimeZoneOptions,
12+
...options,
13+
}).format(date);
714
}

0 commit comments

Comments
 (0)