Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't skip start date in eachWeekendOfInterval #1407

Merged
merged 1 commit into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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