2018-11-14 00:55:07 +00:00
|
|
|
import { helper } from '@ember/component/helper';
|
2021-02-08 20:13:00 +00:00
|
|
|
import { formatDistanceToNow } from 'date-fns';
|
2018-11-14 00:55:07 +00:00
|
|
|
|
|
|
|
export function dateFromNow([date], options = {}) {
|
2021-02-08 20:13:00 +00:00
|
|
|
// check first if string. If it is, it could be ISO format or UTC, either way create a new date object
|
|
|
|
// otherwise it's a number or object and just return
|
|
|
|
let newDate = typeof date === 'string' ? new Date(date) : date;
|
|
|
|
return formatDistanceToNow(newDate, { ...options });
|
2018-11-14 00:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default helper(dateFromNow);
|