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
[bugfix] isBetween should return false for invalid dates #4417
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,7 +226,7 @@ test('is between year', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2010, 5, 6, 7, 8, 9, 10)), | ||
moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later'); | ||
assert.equal(m.isBetween(m, 'year'), false, 'same moments are not between the same year'); | ||
assert.equal(m.isBetween(m, m, 'year'), false, 'same moments are not between the same year'); | ||
assert.equal(+m, +mCopy, 'isBetween year should not change moment'); | ||
}); | ||
|
||
|
@@ -247,7 +247,7 @@ test('is between month', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 11, 6, 7, 8, 9, 10)), | ||
moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is later'); | ||
assert.equal(m.isBetween(m, 'month'), false, 'same moments are not between the same month'); | ||
assert.equal(m.isBetween(m, m, 'month'), false, 'same moments are not between the same month'); | ||
assert.equal(+m, +mCopy, 'isBetween month should not change moment'); | ||
}); | ||
|
||
|
@@ -268,7 +268,7 @@ test('is between day', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 1, 1, 7, 8, 9, 10)), | ||
moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day is later'); | ||
assert.equal(m.isBetween(m, 'day'), false, 'same moments are not between the same day'); | ||
assert.equal(m.isBetween(m, m, 'day'), false, 'same moments are not between the same day'); | ||
assert.equal(+m, +mCopy, 'isBetween day should not change moment'); | ||
}); | ||
|
||
|
@@ -289,7 +289,7 @@ test('is between hour', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 1, 2, 7, 8, 9, 10)), | ||
moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is later'); | ||
assert.equal(m.isBetween(m, 'hour'), false, 'same moments are not between the same hour'); | ||
assert.equal(m.isBetween(m, m, 'hour'), false, 'same moments are not between the same hour'); | ||
assert.equal(+m, +mCopy, 'isBetween hour should not change moment'); | ||
}); | ||
|
||
|
@@ -310,7 +310,7 @@ test('is between minute', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 1, 2, 3, 2, 9, 10)), | ||
moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'minute is later'); | ||
assert.equal(m.isBetween(m, 'minute'), false, 'same moments are not between the same minute'); | ||
assert.equal(m.isBetween(m, m, 'minute'), false, 'same moments are not between the same minute'); | ||
assert.equal(+m, +mCopy, 'isBetween minute should not change moment'); | ||
}); | ||
|
||
|
@@ -331,7 +331,7 @@ test('is between second', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 1, 2, 3, 4, 3, 10)), | ||
moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'second is later'); | ||
assert.equal(m.isBetween(m, 'second'), false, 'same moments are not between the same second'); | ||
assert.equal(m.isBetween(m, m, 'second'), false, 'same moments are not between the same second'); | ||
assert.equal(+m, +mCopy, 'isBetween second should not change moment'); | ||
}); | ||
|
||
|
@@ -352,6 +352,30 @@ test('is between millisecond', function (assert) { | |
assert.equal(m.isBetween( | ||
moment(new Date(2011, 1, 2, 3, 4, 5, 4)), | ||
moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond is later'); | ||
assert.equal(m.isBetween(m, 'millisecond'), false, 'same moments are not between the same millisecond'); | ||
assert.equal(m.isBetween(m, m, 'millisecond'), false, 'same moments are not between the same millisecond'); | ||
assert.equal(+m, +mCopy, 'isBetween millisecond should not change moment'); | ||
}); | ||
|
||
test('is between invalid', function (assert) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a case to show that inclusivity flags don't affect this? For example, #4416 was only an issue with the flags set to '[]' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, tests added for all inclusivity flag combos |
||
var invalid = moment(NaN), | ||
valid = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), | ||
validFrom = moment(new Date(2010, 1, 2, 3, 4, 5, 6)), | ||
validTo = moment(new Date(2012, 1, 2, 3, 4, 5, 6)); | ||
assert.equal(invalid.isBetween(validFrom, validTo), false, 'this instance invalid'); | ||
assert.equal(invalid.isBetween(validFrom, validTo, '[]'), false, 'this instance invalid []'); | ||
assert.equal(invalid.isBetween(validFrom, validTo, '[)'), false, 'this instance invalid [)'); | ||
assert.equal(invalid.isBetween(validFrom, validTo, '(]'), false, 'this instance invalid (]'); | ||
assert.equal(invalid.isBetween(validFrom, validTo, '()'), false, 'this instance invalid ()'); | ||
|
||
assert.equal(valid.isBetween(invalid, validTo), false, 'from invalid moment'); | ||
assert.equal(valid.isBetween(invalid, validTo, '[]'), false, 'from invalid moment []'); | ||
assert.equal(valid.isBetween(invalid, validTo, '[)'), false, 'from invalid moment [)'); | ||
assert.equal(valid.isBetween(invalid, validTo, '(]'), false, 'from invalid moment (]'); | ||
assert.equal(valid.isBetween(invalid, validTo, '()'), false, 'from invalid moment ()'); | ||
|
||
assert.equal(valid.isBetween(validFrom, invalid), false, 'to invalid moment'); | ||
assert.equal(valid.isBetween(validFrom, invalid, '[]'), false, 'to invalid moment []'); | ||
assert.equal(valid.isBetween(validFrom, invalid, '[)'), false, 'to invalid moment [)'); | ||
assert.equal(valid.isBetween(validFrom, invalid, '(]'), false, 'to invalid moment (]'); | ||
assert.equal(valid.isBetween(validFrom, invalid, '()'), false, 'to invalid moment ()'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this.