open-vault/ui/app/helpers/date-from-now.js
Angel Garbarino 5ce35d1c52
Updating date-fns library from 1.x to 2.x (#10848)
* first round of fixes and setup

* test fixes

* fix dumb options on new method

* test fix

* clean up

* fixes

* clean up

* handle utc time

* add changelog
2021-02-08 13:13:00 -07:00

12 lines
471 B
JavaScript

import { helper } from '@ember/component/helper';
import { formatDistanceToNow } from 'date-fns';
export function dateFromNow([date], options = {}) {
// 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 });
}
export default helper(dateFromNow);