Skip to content

Commit

Permalink
Don't skip start date in weekend check
Browse files Browse the repository at this point in the history
  • Loading branch information
vsaarinen authored and kossnocorp committed Sep 6, 2019
1 parent 8ad51a2 commit ac802b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/eachWeekendOfInterval/index.js
Expand Up @@ -39,8 +39,8 @@ export default function eachWeekendOfInterval(interval) {
var dateInterval = eachDayOfInterval(interval)
var weekends = []
var index = 0
while (index++ < dateInterval.length) {
var date = dateInterval[index]
while (index < dateInterval.length) {
var date = dateInterval[index++]
if (isWeekend(date)) {
weekends.push(date)
if (isSunday(date)) index = index + 5
Expand Down
13 changes: 13 additions & 0 deletions src/eachWeekendOfInterval/test.js
Expand Up @@ -18,6 +18,19 @@ describe('eachWeekendOfInterval', function() {
])
})

it('returns all weekends within the interval when starting on a weekend', function() {
var result = eachWeekendOfInterval({
start: new Date(2018, 8 /* Sept */, 22),
end: new Date(2018, 8 /* Sept */, 30)
})
assert.deepEqual(result, [
new Date(2018, 8 /* Sept */, 22),
new Date(2018, 8 /* Sept */, 23),
new Date(2018, 8 /* Sept */, 29),
new Date(2018, 8 /* Sept */, 30)
])
})

it('throws `RangeError` invalid interval start date is used', function() {
// $ExpectedMistake
var block = eachWeekendOfInterval.bind(null, {
Expand Down

0 comments on commit ac802b2

Please sign in to comment.