This is the method I use to compare the current date and leave date taken by staff in order to show the upcoming and past leaves.
For the displayPast() function I have take in the end date and object. The end date is used to compare to the current date and the object is needed to display the leaveType etc.
methods: {
displayPast(endDate, obj){
let currentDate = new Date()
console.log(currentDate)
let disDate = new Date(endDate)
var html = ``
// console.log(disDate)
// This is the code where I compare the dates to decide to display upcoming or past leaves.
if(currentDate > disDate){
console.log(`${currentDate} is greater than - past ${disDate}`)
html +=
`
<table class="displayLeaveTable">
<tbody>
<tr>
<td class="body h5">Leave Type:</td>
<td class="body">${obj.leaveType}</td>
<td class="body h5 date">${obj.startDate}-</td>
<td class="body h5 date">${obj.endDate}</td>
</tr>
</tbody>
</table>
`
return html
} else if(currentDate < disDate){
console.log(`${disDate} is greater than - upcoming ${currentDate}`)
html +=
`
<table class="displayLeaveTable">
<tbody>
<tr>
<td class="body h5">Leave Type:</td>
<td class="body">${obj.leaveType}</td>
<td class="body h5 date">${obj.startDate}-</td>
<td class="body h5 date">${obj.endDate}</td>
</tr>
</tbody>
</table>
`
return html
} else{
console.log(`Both dates are equal`)
}
}
However, I do not know why it is still showing the same information for both upcoming and past.
<!-- Tabs to show upcoming and past leaves -->
<TabsWrapper>
<Tab title="Upcoming">
<div class="tabDivOne" v-if="users.leaveType != ''">
<span v-html="this.displayPast(users.endDate, users)"></span>
</div>
</Tab>
<Tab title="Past">
<div class="tabDivTwo" v-if="users.leaveType != ''">
<span v-html="this.displayPast(users.endDate, users)"></span>
</div>
</Tab>
</TabsWrapper>
In the above image the information should be shown in the Past tab rather than in the Upcoming tab. Hence, I do not know what is the issue with my codes which have caused the incorrect output.