fixed showing closest reservation
This commit is contained in:
@@ -311,9 +311,16 @@ Vue.component('asset-borrow-return-widget', {
|
|||||||
},
|
},
|
||||||
nextReservation() {
|
nextReservation() {
|
||||||
if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null;
|
if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null;
|
||||||
|
|
||||||
const now = window.moment().unix();
|
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: {
|
methods: {
|
||||||
formatDate(timestamp, format) {
|
formatDate(timestamp, format) {
|
||||||
|
|||||||
Reference in New Issue
Block a user