mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
20 lines
540 B
JavaScript
20 lines
540 B
JavaScript
|
import moment from 'moment';
|
||
|
import {helper} from '@ember/component/helper';
|
||
|
|
||
|
export function mostRecentlyUpdated(objs) {
|
||
|
const items = [...(objs || [])];
|
||
|
|
||
|
(items || []).sort((a, b) => {
|
||
|
const momentA = moment(a.updatedAtUTC || a.updatedAt || a.updated_at);
|
||
|
const momentB = moment(b.updatedAtUTC || b.updatedAt || b.updated_at);
|
||
|
|
||
|
return momentB.valueOf() - momentA.valueOf();
|
||
|
});
|
||
|
|
||
|
return items[0] || null;
|
||
|
}
|
||
|
|
||
|
export default helper(function ([items = []]) {
|
||
|
return mostRecentlyUpdated(items);
|
||
|
});
|