about summary refs log tree commit diff
path: root/src/lib/strings/time.ts
diff options
context:
space:
mode:
authorKuwa Lee <kuwalee1069@gmail.com>2024-06-19 02:47:38 +0800
committerGitHub <noreply@github.com>2024-06-19 02:47:38 +0800
commita6d49062e6d50b7c9a6c0d50c38fcfeb8f63e46f (patch)
tree65ef4f28c174d1da9c8f7085635b05b754e95746 /src/lib/strings/time.ts
parentfad73fe9281baee8409a65a10923749ec24dfd68 (diff)
parent35e54e24a0b08ce0f2e3389aeb4fb0f29778170e (diff)
downloadvoidsky-a6d49062e6d50b7c9a6c0d50c38fcfeb8f63e46f.tar.zst
Merge branch 'bluesky-social:main' into zh
Diffstat (limited to 'src/lib/strings/time.ts')
-rw-r--r--src/lib/strings/time.ts42
1 files changed, 0 insertions, 42 deletions
diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts
index 8de4b52ae..1194e0240 100644
--- a/src/lib/strings/time.ts
+++ b/src/lib/strings/time.ts
@@ -1,45 +1,3 @@
-const NOW = 5
-const MINUTE = 60
-const HOUR = MINUTE * 60
-const DAY = HOUR * 24
-const MONTH_30 = DAY * 30
-const MONTH = DAY * 30.41675 // This results in 365.001 days in a year, which is close enough for nearly all cases
-export function ago(date: number | string | Date): string {
-  let ts: number
-  if (typeof date === 'string') {
-    ts = Number(new Date(date))
-  } else if (date instanceof Date) {
-    ts = Number(date)
-  } else {
-    ts = date
-  }
-  const diffSeconds = Math.floor((Date.now() - ts) / 1e3)
-  if (diffSeconds < NOW) {
-    return `now`
-  } else if (diffSeconds < MINUTE) {
-    return `${diffSeconds}s`
-  } else if (diffSeconds < HOUR) {
-    return `${Math.floor(diffSeconds / MINUTE)}m`
-  } else if (diffSeconds < DAY) {
-    return `${Math.floor(diffSeconds / HOUR)}h`
-  } else if (diffSeconds < MONTH_30) {
-    return `${Math.round(diffSeconds / DAY)}d`
-  } else {
-    let months = diffSeconds / MONTH
-    if (months % 1 >= 0.9) {
-      months = Math.ceil(months)
-    } else {
-      months = Math.floor(months)
-    }
-
-    if (months < 12) {
-      return `${months}mo`
-    } else {
-      return new Date(ts).toLocaleDateString()
-    }
-  }
-}
-
 export function niceDate(date: number | string | Date) {
   const d = new Date(date)
   return `${d.toLocaleDateString('en-us', {