File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -20,5 +20,18 @@ export function timeAgo(date: Date | string): string {
20
20
// Force english because JSR is an English-only project
21
21
// @ts -ignore - TS doesn't know about this API yet
22
22
const formatter = new Intl . DurationFormat ( "en" , { style : "long" } ) ;
23
- return formatter . format ( duration ) + " ago" ;
23
+
24
+ if ( duration . years >= 1 ) {
25
+ return formatter . format ( { years : duration . years } ) + " ago" ;
26
+ } else if ( duration . months >= 1 ) {
27
+ return formatter . format ( { months : duration . months } ) + " ago" ;
28
+ } else if ( duration . days >= 1 ) {
29
+ return formatter . format ( { days : duration . days } ) + " ago" ;
30
+ } else if ( duration . hours >= 1 ) {
31
+ return formatter . format ( { hours : duration . hours } ) + " ago" ;
32
+ } else if ( duration . minutes >= 1 ) {
33
+ return formatter . format ( { minutes : duration . minutes } ) + " ago" ;
34
+ } else {
35
+ return formatter . format ( { seconds : duration . seconds } ) + " ago" ;
36
+ }
24
37
}
You can’t perform that action at this time.
0 commit comments