File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
ui/packages/platform/src/utils Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 66 */
77
88import moment from 'moment'
9+ import { pluralize } from "./time" ;
910
1011const Format = {
1112 formatSeconds : function ( seconds : number , decimal : number , separator = ' ' ) {
@@ -266,6 +267,7 @@ const Format = {
266267 timeAgo : function ( date : string | Date ) : string | null {
267268 if ( ! date ) return null
268269
270+
269271 const now = new Date ( ) ;
270272 const past = new Date ( date ) ;
271273 const diff = Math . abs ( now . getTime ( ) - past . getTime ( ) ) ;
@@ -275,13 +277,13 @@ const Format = {
275277 const days = Math . floor ( hours / 24 ) ;
276278
277279 if ( seconds < 60 ) {
278- return `${ seconds } seconds ago` ;
280+ return `${ seconds } ${ pluralize ( 'second' , ' seconds' ) ( seconds ) } ago` ;
279281 } else if ( minutes < 60 ) {
280- return `${ minutes } minutes ago` ;
282+ return `${ minutes } ${ pluralize ( 'minute' , ' minutes' ) ( minutes ) } ago` ;
281283 } else if ( hours < 24 ) {
282- return `${ hours } hours ago` ;
284+ return `${ hours } ${ pluralize ( 'hour' , ' hours' ) ( hours ) } ago` ;
283285 } else {
284- return `${ days } days ago` ;
286+ return `${ days } ${ pluralize ( 'day' , ' days' ) ( seconds ) } ago` ;
285287 }
286288 }
287289}
Original file line number Diff line number Diff line change 1- const pluralize = ( single : string , multiple : string ) => ( val : number ) =>
1+ export const pluralize = ( single : string , multiple : string ) => ( val : number ) =>
22 val === 1 ? single : multiple
33
44const MS_IN_SECOND = 1000
You can’t perform that action at this time.
0 commit comments