about summary refs log tree commit diff
path: root/src/lib/hooks/useTimeAgo.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-06-18 13:50:07 -0500
committerGitHub <noreply@github.com>2024-06-18 21:50:07 +0300
commit983d85384b9e736193e6c89107df5ced447a056a (patch)
tree8ecc5157012be5deda6ac44a86c6c3ad409c9a9f /src/lib/hooks/useTimeAgo.ts
parentfb76265fcc0042bc8cd5a3f7563790f495d3ae8c (diff)
downloadvoidsky-983d85384b9e736193e6c89107df5ced447a056a.tar.zst
Force callers of `getTimeAgo` to pass in the value for "now" (#4560)
* Remove icky hook for now

* Force callers of getTimeAgo to pass in the 'now' value

* Update usage in Newskie dialog
Diffstat (limited to 'src/lib/hooks/useTimeAgo.ts')
-rw-r--r--src/lib/hooks/useTimeAgo.ts17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/lib/hooks/useTimeAgo.ts b/src/lib/hooks/useTimeAgo.ts
index 5f0782f96..efcb4754b 100644
--- a/src/lib/hooks/useTimeAgo.ts
+++ b/src/lib/hooks/useTimeAgo.ts
@@ -1,4 +1,4 @@
-import {useCallback, useMemo} from 'react'
+import {useCallback} from 'react'
 import {msg, plural} from '@lingui/macro'
 import {I18nContext, useLingui} from '@lingui/react'
 import {differenceInSeconds} from 'date-fns'
@@ -12,25 +12,16 @@ export function useGetTimeAgo() {
   const {_} = useLingui()
   return useCallback(
     (
-      date: number | string | Date,
+      earlier: number | string | Date,
+      later: number | string | Date,
       options?: Omit<TimeAgoOptions, 'lingui'>,
     ) => {
-      return dateDiff(date, Date.now(), {lingui: _, format: options?.format})
+      return dateDiff(earlier, later, {lingui: _, format: options?.format})
     },
     [_],
   )
 }
 
-export function useTimeAgo(
-  date: number | string | Date,
-  options?: Omit<TimeAgoOptions, 'lingui'>,
-): string {
-  const timeAgo = useGetTimeAgo()
-  return useMemo(() => {
-    return timeAgo(date, {...options})
-  }, [date, options, timeAgo])
-}
-
 const NOW = 5
 const MINUTE = 60
 const HOUR = MINUTE * 60