diff --git a/public/js/pages/AssetManagement/AssetManagement.js b/public/js/pages/AssetManagement/AssetManagement.js index 31be0529f..9bc533915 100644 --- a/public/js/pages/AssetManagement/AssetManagement.js +++ b/public/js/pages/AssetManagement/AssetManagement.js @@ -311,9 +311,16 @@ Vue.component('asset-borrow-return-widget', { }, nextReservation() { if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null; + const now = window.moment().unix(); - return this.rowData.reservations.find(r => r.startDate > now); + return this.rowData.reservations.reduce((closest, current) => { + const closestDiff = Math.abs(closest.startDate - now); + const currentDiff = Math.abs(current.startDate - now); + + return currentDiff < closestDiff ? current : closest; + }); } + }, methods: { formatDate(timestamp, format) {