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

[bugfix] isBetween should return false for invalid dates #4417

Merged
merged 3 commits into from Dec 13, 2018

Conversation

ashsearle
Copy link
Contributor

Changes to isBetween to fix a couple of issues from #4416 and #4114 .

Documentation states that invalid.isBetween(another, another) should return false, but #4416 highlights a case where it doesn't. This PR fixes #4416 and ensures isBetween(..) return false no matter what unit or inclusivity flags are used:

// These should all return false:
invalid.isBetween(another, another);
valid.isBetween(invalid, another);
valid.isBetween(another, invalid);

The conversation in #4114 highlights some examples that are incompatible with current typescript bindings. This PR fixes the typescript binding to match example code - explicitly allowing null to be passed in as the units value, - and this now follows a faster code path to avoid cloning moments unnecessarily - i.e. fixes #4114.

@ashsearle ashsearle closed this Feb 1, 2018
@ashsearle ashsearle reopened this Feb 1, 2018
@ashsearle ashsearle changed the title [bugfix]: isBetween should return false for invalid dates bugfix: isBetween should return false for invalid dates Feb 1, 2018
@ashsearle ashsearle changed the title bugfix: isBetween should return false for invalid dates [bugfix] isBetween should return false for invalid dates Feb 1, 2018
@coveralls
Copy link

coveralls commented Apr 13, 2018

Coverage Status

Coverage increased (+0.3%) to 94.76% when pulling fd14000 on ashsearle:fix/4114 into 07d88ae on moment:develop.

@@ -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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this.

assert.equal(+m, +mCopy, 'isBetween millisecond should not change moment');
});

test('is between invalid', function (assert) {
Copy link
Member

Choose a reason for hiding this comment

The 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 '[]'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tests added for all inclusivity flag combos

@ichernev
Copy link
Contributor

@ashsearle thanks a lot! Very well done!

@marwahaha marwahaha merged commit 40b52a0 into moment:develop Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants