From a26db9ea94c60be3018065fc7959c9a74e0be319 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 7 Feb 2024 15:45:39 -0600 Subject: [PATCH] upgrade date-fns thru major version, update calls accordingly --- app/util/date.ts | 33 ++++++++++++++------------------- package-lock.json | 27 +++++++++------------------ package.json | 2 +- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/app/util/date.ts b/app/util/date.ts index acc4a8bec..1a9b2317b 100644 --- a/app/util/date.ts +++ b/app/util/date.ts @@ -5,7 +5,7 @@ * * Copyright Oxide Computer Company */ -import { formatDistanceToNowStrict } from 'date-fns' +import { formatDistanceToNowStrict, type FormatDistanceToNowStrictOptions } from 'date-fns' // locale setup and formatDistance function copied from here and modified // https://github.com/date-fns/date-fns/blob/56a3856/src/locale/en-US/_lib/formatDistance/index.js @@ -29,21 +29,16 @@ const formatDistanceLocale = { almostXYears: '~ {{count}}y', } -interface Options { - addSuffix: boolean -} - -function formatDistance( - token: keyof typeof formatDistanceLocale, - count: string, - options: Options -) { - const result = formatDistanceLocale[token]?.replace('{{count}}', count) - if (result && options.addSuffix) { - return result + ' ago' - } - return result -} - -export const timeAgoAbbr = (d: Date, options: Options = { addSuffix: false }) => - formatDistanceToNowStrict(d, { ...options, locale: { formatDistance } }) +export const timeAgoAbbr = (d: Date, options?: FormatDistanceToNowStrictOptions) => + formatDistanceToNowStrict(d, { + ...options, + locale: { + formatDistance: (token, count, options) => { + const result = formatDistanceLocale[token]?.replace('{{count}}', count.toString()) + if (result && options?.addSuffix) { + return result + ' ago' + } + return result + }, + }, + }) diff --git a/package-lock.json b/package-lock.json index e8e85f290..b8051deb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@tanstack/react-query-devtools": "^5.17.4", "@tanstack/react-table": "^8.11.3", "classnames": "^2.5.1", - "date-fns": "^2.30.0", + "date-fns": "^3.3.1", "filesize": "^10.1.0", "lodash.throttle": "^4.1.1", "match-sorter": "^6.3.1", @@ -8553,18 +8553,12 @@ } }, "node_modules/date-fns": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", - "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", - "dependencies": { - "@babel/runtime": "^7.21.0" - }, - "engines": { - "node": ">=0.11" - }, + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.3.1.tgz", + "integrity": "sha512-y8e109LYGgoQDveiEBD3DYXKba1jWf5BA8YU1FL5Tvm0BTdEfy54WLCwnuYWZNnzzvALy/QQ4Hov+Q9RVRv+Zw==", "funding": { - "type": "opencollective", - "url": "https://opencollective.com/date-fns" + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" } }, "node_modules/debug": { @@ -27736,12 +27730,9 @@ } }, "date-fns": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", - "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", - "requires": { - "@babel/runtime": "^7.21.0" - } + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.3.1.tgz", + "integrity": "sha512-y8e109LYGgoQDveiEBD3DYXKba1jWf5BA8YU1FL5Tvm0BTdEfy54WLCwnuYWZNnzzvALy/QQ4Hov+Q9RVRv+Zw==" }, "debug": { "version": "4.3.4", diff --git a/package.json b/package.json index 7a2921f6d..af3d3ad8f 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@tanstack/react-query-devtools": "^5.17.4", "@tanstack/react-table": "^8.11.3", "classnames": "^2.5.1", - "date-fns": "^2.30.0", + "date-fns": "^3.3.1", "filesize": "^10.1.0", "lodash.throttle": "^4.1.1", "match-sorter": "^6.3.1",