Skip to content

Commit

Permalink
fix: change range check to exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Jul 25, 2018
1 parent 75244d4 commit d9a9be2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function isWithinRange (start, end, dateTime) {
return dateTime.isBetween(start, end, null, '[]')
return dateTime.isBetween(start, end, null, '()')
}
33 changes: 18 additions & 15 deletions test/handle-diary-entry-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,26 +287,29 @@ describe('Tests the state resource which handle diary entries', function () {
}
})

it('should test the function to check if a date time is within a range', () => {
const a = moment('2018-04-25T21:30:00')
const b = moment('2018-04-25T12:30:00')
const c = moment('2018-04-25T12:00:00')
const d = moment('2018-04-25T13:30:00')
it('should test the function to check if a date time is within a range (exclusive)', () => {
const good = [
moment('2018-04-25T08:30:00'),
moment('2018-04-25T21:30:00'),
moment('2018-04-25T13:30:00'),
moment('2018-04-25T12:00:00')
]
const bad = [
moment('2018-04-25T12:30:00'),
moment('2018-04-25T12:10:00'),
moment('2018-04-25T13:00:00')
]

const start = moment('2018-04-25T12:00:00')
const end = moment('2018-04-25T13:30:00')

const valueA = isWithinRange(start, end, a)
expect(valueA).to.eql(false)

const valueB = isWithinRange(start, end, b)
expect(valueB).to.eql(true)

const valueC = isWithinRange(start, end, c)
expect(valueC).to.eql(true)
for (let time of good) {
expect(isWithinRange(start, end, time)).to.eql(false)
}

const valueD = isWithinRange(start, end, d)
expect(valueD).to.eql(true)
for (let time of bad) {
expect(isWithinRange(start, end, time)).to.eql(true)
}
})

it('should shutdown Tymly', async () => {
Expand Down

0 comments on commit d9a9be2

Please sign in to comment.