Skip to content

Commit a26db9e

Browse files
committed
upgrade date-fns thru major version, update calls accordingly
1 parent 3dd635a commit a26db9e

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

app/util/date.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8-
import { formatDistanceToNowStrict } from 'date-fns'
8+
import { formatDistanceToNowStrict, type FormatDistanceToNowStrictOptions } from 'date-fns'
99

1010
// locale setup and formatDistance function copied from here and modified
1111
// https://github.com/date-fns/date-fns/blob/56a3856/src/locale/en-US/_lib/formatDistance/index.js
@@ -29,21 +29,16 @@ const formatDistanceLocale = {
2929
almostXYears: '~ {{count}}y',
3030
}
3131

32-
interface Options {
33-
addSuffix: boolean
34-
}
35-
36-
function formatDistance(
37-
token: keyof typeof formatDistanceLocale,
38-
count: string,
39-
options: Options
40-
) {
41-
const result = formatDistanceLocale[token]?.replace('{{count}}', count)
42-
if (result && options.addSuffix) {
43-
return result + ' ago'
44-
}
45-
return result
46-
}
47-
48-
export const timeAgoAbbr = (d: Date, options: Options = { addSuffix: false }) =>
49-
formatDistanceToNowStrict(d, { ...options, locale: { formatDistance } })
32+
export const timeAgoAbbr = (d: Date, options?: FormatDistanceToNowStrictOptions) =>
33+
formatDistanceToNowStrict(d, {
34+
...options,
35+
locale: {
36+
formatDistance: (token, count, options) => {
37+
const result = formatDistanceLocale[token]?.replace('{{count}}', count.toString())
38+
if (result && options?.addSuffix) {
39+
return result + ' ago'
40+
}
41+
return result
42+
},
43+
},
44+
})

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@tanstack/react-query-devtools": "^5.17.4",
4646
"@tanstack/react-table": "^8.11.3",
4747
"classnames": "^2.5.1",
48-
"date-fns": "^2.30.0",
48+
"date-fns": "^3.3.1",
4949
"filesize": "^10.1.0",
5050
"lodash.throttle": "^4.1.1",
5151
"match-sorter": "^6.3.1",

0 commit comments

Comments
 (0)