From 3c27711df2d59afcb4b952666240429483ab1c70 Mon Sep 17 00:00:00 2001 From: Brandon McConnell Date: Sun, 31 Mar 2024 19:07:51 -0700 Subject: [PATCH 1/3] Resolve time discrepancy and remove need for 3rd-party package tinytime --- package-lock.json | 5 ----- package.json | 1 - src/components/PostItem.js | 8 ++++++- src/layouts/BlogPostLayout.js | 11 ++++++++- src/layouts/JobPostingLayout.js | 10 ++++++++- src/pages/blog/index.js | 8 ++++++- src/utils/formatDate.js | 40 ++++++++++++++++++++++++++++----- 7 files changed, 68 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a060ed91..163287afa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,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", @@ -10232,10 +10231,6 @@ "dev": true, "license": "MIT" }, - "node_modules/tinytime": { - "version": "0.2.6", - "license": "MIT" - }, "node_modules/tmp": { "version": "0.0.33", "dev": true, diff --git a/package.json b/package.json index 057efa9de..53bd56f07 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/PostItem.js b/src/components/PostItem.js index 39ff0e629..f5a15d60a 100644 --- a/src/components/PostItem.js +++ b/src/components/PostItem.js @@ -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 (
- + @@ -50,7 +59,7 @@ export function BlogPostLayout({ children, meta }) { className={clsx('absolute top-0 inset-x-0 text-slate-700 dark:text-slate-400')} > diff --git a/src/layouts/JobPostingLayout.js b/src/layouts/JobPostingLayout.js index c8f6e5f3c..ee03680f9 100644 --- a/src/layouts/JobPostingLayout.js +++ b/src/layouts/JobPostingLayout.js @@ -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 (
@@ -203,7 +211,7 @@ export function JobPostingLayout({ children, meta }) {

Closes on{' '}

diff --git a/src/pages/blog/index.js b/src/pages/blog/index.js index f48d000eb..fb4f52b15 100644 --- a/src/pages/blog/index.js +++ b/src/pages/blog/index.js @@ -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 (
@@ -52,7 +58,7 @@ export default function Blog({ posts }) {
Date
- +
diff --git a/src/utils/formatDate.js b/src/utils/formatDate.js index 18ea750e4..4da744f64 100644 --- a/src/utils/formatDate.js +++ b/src/utils/formatDate.js @@ -1,7 +1,37 @@ -import tinytime from 'tinytime' +export const DateTimeFormats = { + short: { + month: 'long', + day: 'numeric', + year: 'numeric', + }, + medium: { + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + year: 'numeric' + }, + BLOG_POST: { + weekday: 'long', + month: 'long', + day: 'numeric', + year: 'numeric', + hour: 'numeric', + minute: 'numeric', + } +} + +export function formatDate(dateString, options = DateTimeFormats.simple) { + 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); } From 682711df55e15146c3bad9c9e5b0636034f4c79a Mon Sep 17 00:00:00 2001 From: Brandon McConnell Date: Sun, 31 Mar 2024 20:36:40 -0700 Subject: [PATCH 2/3] Remove unused `DateTimeFormats` --- src/utils/formatDate.js | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/utils/formatDate.js b/src/utils/formatDate.js index 4da744f64..03d001413 100644 --- a/src/utils/formatDate.js +++ b/src/utils/formatDate.js @@ -1,29 +1,6 @@ -export const DateTimeFormats = { - short: { - month: 'long', - day: 'numeric', - year: 'numeric', - }, - medium: { - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - year: 'numeric' - }, - BLOG_POST: { - weekday: 'long', - month: 'long', - day: 'numeric', - year: 'numeric', - hour: 'numeric', - minute: 'numeric', - } -} - -export function formatDate(dateString, options = DateTimeFormats.simple) { +export function formatDate(dateString, options) { const date = new Date(dateString); - const defaultTimeZoneOptions = options.hour + const defaultTimeZoneOptions = options?.hour ? { timeZoneName: 'shortGeneric', timeZone: 'America/New_York', From 42d3fde606cdc54065502aeaf85e296b7a6ce18d Mon Sep 17 00:00:00 2001 From: Brandon McConnell Date: Mon, 1 Apr 2024 09:49:05 -0700 Subject: [PATCH 3/3] Resolve DateTimeFormat for blog post dates --- src/layouts/BlogPostLayout.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/layouts/BlogPostLayout.js b/src/layouts/BlogPostLayout.js index 7551ca55a..4eac9966f 100644 --- a/src/layouts/BlogPostLayout.js +++ b/src/layouts/BlogPostLayout.js @@ -11,8 +11,6 @@ const dateFormat = { month: 'long', day: 'numeric', year: 'numeric', - hour: 'numeric', - minute: 'numeric', } export function BlogPostLayout({ children, meta }) {