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 {
2020 // Force english because JSR is an English-only project
2121 // @ts -ignore - TS doesn't know about this API yet
2222 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+ }
2437}
You can’t perform that action at this time.
0 commit comments