2018-11-25 19:33:59 +01:00
|
|
|
import { format } from '../_thirdparty/timeago/timeago'
|
2018-11-25 10:20:58 +01:00
|
|
|
import { mark, stop } from '../_utils/marks'
|
|
|
|
|
2019-05-27 03:48:04 +02:00
|
|
|
// Format a date in the past
|
2019-05-27 01:01:14 +02:00
|
|
|
export function formatTimeagoDate (date, now) {
|
2018-11-25 10:20:58 +01:00
|
|
|
mark('formatTimeagoDate')
|
2019-05-27 01:01:14 +02:00
|
|
|
// use Math.max() to avoid things like "in 10 seconds" when the timestamps are slightly off
|
|
|
|
let res = format(date, Math.max(now, date))
|
2018-11-25 10:20:58 +01:00
|
|
|
stop('formatTimeagoDate')
|
|
|
|
return res
|
|
|
|
}
|
2019-05-27 03:48:04 +02:00
|
|
|
|
|
|
|
// Format a date in the future
|
|
|
|
export function formatTimeagoFutureDate (date, now) {
|
|
|
|
mark('formatTimeagoFutureDate')
|
|
|
|
// use Math.min() for same reason as above
|
|
|
|
let res = format(date, Math.min(now, date))
|
|
|
|
stop('formatTimeagoFutureDate')
|
|
|
|
return res
|
|
|
|
}
|