File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -25,21 +25,24 @@ type FetchParams = {
2525} ;
2626
2727export const generateElapsedTimeText = ( timeString : string ) => {
28- const currentTime = Date . now ( ) ;
28+ const currentTime = new Date ( ) . getTime ( ) ;
2929 const targetTime = new Date ( timeString ) . getTime ( ) ;
30- const timeDiff = currentTime - targetTime ;
30+ const millisecondsDiff = currentTime - targetTime ;
3131
32- const seconds = Math . floor ( timeDiff / 1000 ) ;
32+ const seconds = Math . floor ( millisecondsDiff / 1000 ) ;
3333 const minutes = Math . floor ( seconds / 60 ) ;
3434 const hours = Math . floor ( minutes / 60 ) ;
3535 const days = Math . floor ( hours / 24 ) ;
36+ const months = Math . floor ( days / 30 ) ;
3637 const years = Math . floor ( days / 365 ) ;
3738
38- if ( timeDiff < 60000 ) return "Just now" ;
39+ if ( millisecondsDiff < 60000 ) return "Just now" ;
3940 else if ( minutes < 60 )
4041 return minutes === 1 ? "1 minute ago" : `${ minutes } minutes ago` ;
4142 else if ( hours < 24 ) return hours === 1 ? "1 hour ago" : `${ hours } hours ago` ;
42- else if ( days < 365 ) return days === 1 ? "1 day ago" : `${ days } days ago` ;
43+ else if ( days < 30 ) return days === 1 ? "1 day ago" : `${ days } days ago` ;
44+ else if ( months < 12 )
45+ return months === 1 ? "1 month ago" : `${ months } months ago` ;
4346 else return years === 1 ? "1 year ago" : `${ years } years ago` ;
4447} ;
4548
You can’t perform that action at this time.
0 commit comments