feat: add date time util

This commit is contained in:
Henry Li
2026-01-17 15:44:38 +08:00
parent 31510879f2
commit c38dfdf0e0
3 changed files with 16 additions and 0 deletions

View File

@@ -39,6 +39,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"date-fns": "^4.1.0",
"embla-carousel-react": "^8.6.0",
"hast": "^1.0.0",
"lucide-react": "^0.562.0",

View File

@@ -77,6 +77,9 @@ importers:
cmdk:
specifier: ^1.1.1
version: 1.1.1(@types/react-dom@19.2.3(@types/react@19.2.8))(@types/react@19.2.8)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
date-fns:
specifier: ^4.1.0
version: 4.1.0
embla-carousel-react:
specifier: ^8.6.0
version: 8.6.0(react@19.2.3)
@@ -2503,6 +2506,9 @@ packages:
resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==}
engines: {node: '>= 0.4'}
date-fns@4.1.0:
resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
dayjs@1.11.19:
resolution: {integrity: sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==}
@@ -6969,6 +6975,8 @@ snapshots:
es-errors: 1.3.0
is-data-view: 1.0.2
date-fns@4.1.0: {}
dayjs@1.11.19: {}
debug@3.2.7:

View File

@@ -0,0 +1,7 @@
import { formatDistanceToNow } from "date-fns";
export function formatTimeAgo(date: Date | string | number) {
return formatDistanceToNow(date, {
addSuffix: true,
});
}