Merge pull request #73 from jedmund/fix-70

Fix #70: Malformed dates causing pages with timestamps to fail
This commit is contained in:
Justin Edmund 2022-12-27 10:40:59 -08:00 committed by GitHub
commit 14e87895a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import { useRouter } from 'next/router'
import { useSnapshot } from 'valtio'
import { useTranslation } from 'next-i18next'
import classNames from 'classnames'
import 'fix-date'
import { accountState } from '~utils/accountState'
import { formatTimeAgo } from '~utils/timeAgo'

11
package-lock.json generated
View file

@ -18,6 +18,7 @@
"axios": "^0.25.0",
"classnames": "^2.3.1",
"cookies-next": "^2.1.1",
"fix-date": "^1.1.6",
"i18next": "^21.6.13",
"i18next-browser-languagedetector": "^6.1.3",
"i18next-http-backend": "^1.3.2",
@ -5528,6 +5529,11 @@
"node": ">=4"
}
},
"node_modules/fix-date": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/fix-date/-/fix-date-1.1.6.tgz",
"integrity": "sha512-YN9InFic51O88wkDUSCKoj0pbWS7p4ucviZzeKdiXg48vtfpqlHYYg/U92DwX+S4YSzNjtHKeHYiuVo86Gatpw=="
},
"node_modules/flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",
@ -12030,6 +12036,11 @@
"locate-path": "^2.0.0"
}
},
"fix-date": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/fix-date/-/fix-date-1.1.6.tgz",
"integrity": "sha512-YN9InFic51O88wkDUSCKoj0pbWS7p4ucviZzeKdiXg48vtfpqlHYYg/U92DwX+S4YSzNjtHKeHYiuVo86Gatpw=="
},
"flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",

View file

@ -23,6 +23,7 @@
"axios": "^0.25.0",
"classnames": "^2.3.1",
"cookies-next": "^2.1.1",
"fix-date": "^1.1.6",
"i18next": "^21.6.13",
"i18next-browser-languagedetector": "^6.1.3",
"i18next-http-backend": "^1.3.2",

View file

@ -13,7 +13,7 @@ export function formatTimeAgo(date: Date, locale: string = 'en-us') {
let duration = (date.getTime() - new Date().getTime()) / 1000
for (let i = 0; i <= DIVISIONS.length; i++) {
for (let i = 0; i < DIVISIONS.length; i++) {
const division = DIVISIONS[i]
if (Math.abs(duration) < division.amount) {