import { pluralize } from '../util/strings' ; const MINUTE = 60 ; const HOUR = MINUTE * 60 ; const DAY = HOUR * 24 ; const WEEK = DAY * 7 ; const MONTH = DAY * 30 ; const YEAR = DAY * 365 ; export const getTimeSinceToday = date => { const updateTimeSeconds = new Date ( date ) . getTime ( ) ; const currentTimeSeconds = new Date ( ) . getTime ( ) ; let seconds = Math . abs ( currentTimeSeconds - updateTimeSeconds ) / 1000 ; seconds = seconds > 0 ? seconds : 1 ; let [ value , unit ] = seconds < MINUTE ? [ Math . round ( seconds ) , 'second' ] : seconds < HOUR ? [ Math . round ( seconds / MINUTE ) , 'minute' ] : seconds < DAY ? [ Math . round ( seconds / HOUR ) , 'hour' ] : seconds < WEEK ? [ Math . round ( seconds / DAY ) , 'day' ] : seconds < MONTH ? [ Math . round ( seconds / WEEK ) , 'week' ] : seconds < YEAR ? [ Math . round ( seconds / MONTH ) , 'month' ] : [ Math . round ( seconds / YEAR ) , 'year' ] ; unit = pluralize ( unit , value ) ; return `${ value } ${ unit } ago` ; } ;