Skip to content

Commit

Permalink
feat: if date is today only get available slots after current time
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda authored and Meena Hoda committed Aug 6, 2019
1 parent 589818c commit a91181e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/components/state-resources/get-available-diary-slots/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const getAvailableDiarySlots = require('./helpers/generate-time-slots')
const moment = require('moment')

Expand Down Expand Up @@ -43,6 +41,18 @@ module.exports = class GetAvailableDiarySlots {
remove.push(index)
}
})

const today = moment(new Date())
const isToday = moment(event.date).format('YYYY-MM-DD') === today.format('YYYY-MM-DD')

if (isToday) {
const timeSlot_ = moment(today.format('YYYY-MM-DD') + 'T' + timeSlot[0])
const isBefore = moment(timeSlot_).isBefore(today)

if (isBefore) {
remove.push(index)
}
}
})

const final = availableTimes.filter((e, idx) => !remove.includes(idx))
Expand Down

0 comments on commit a91181e

Please sign in to comment.