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 6
6
*/
7
7
8
8
import moment from 'moment'
9
+ import { pluralize } from "./time" ;
9
10
10
11
const Format = {
11
12
formatSeconds : function ( seconds : number , decimal : number , separator = ' ' ) {
@@ -266,6 +267,7 @@ const Format = {
266
267
timeAgo : function ( date : string | Date ) : string | null {
267
268
if ( ! date ) return null
268
269
270
+
269
271
const now = new Date ( ) ;
270
272
const past = new Date ( date ) ;
271
273
const diff = Math . abs ( now . getTime ( ) - past . getTime ( ) ) ;
@@ -275,13 +277,13 @@ const Format = {
275
277
const days = Math . floor ( hours / 24 ) ;
276
278
277
279
if ( seconds < 60 ) {
278
- return `${ seconds } seconds ago` ;
280
+ return `${ seconds } ${ pluralize ( 'second' , ' seconds' ) ( seconds ) } ago` ;
279
281
} else if ( minutes < 60 ) {
280
- return `${ minutes } minutes ago` ;
282
+ return `${ minutes } ${ pluralize ( 'minute' , ' minutes' ) ( minutes ) } ago` ;
281
283
} else if ( hours < 24 ) {
282
- return `${ hours } hours ago` ;
284
+ return `${ hours } ${ pluralize ( 'hour' , ' hours' ) ( hours ) } ago` ;
283
285
} else {
284
- return `${ days } days ago` ;
286
+ return `${ days } ${ pluralize ( 'day' , ' days' ) ( seconds ) } ago` ;
285
287
}
286
288
}
287
289
}
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 ) =>
2
2
val === 1 ? single : multiple
3
3
4
4
const MS_IN_SECOND = 1000
You can’t perform that action at this time.
0 commit comments