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

configure inclusivity on isBetween #385

Closed
Farkal opened this issue Oct 16, 2018 · 3 comments
Closed

configure inclusivity on isBetween #385

Farkal opened this issue Oct 16, 2018 · 3 comments

Comments

@Farkal
Copy link

Farkal commented Oct 16, 2018

https://momentjs.com/docs/#/query/is-between/

Actual state:

dayjs('2010-10-20').isBetween('2010-10-20', dayjs('2010-10-20'));   // false
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-20'));   // false
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-21'));   // true

We must be able to enable inclusivity by passing a string (like in moment):

moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '()'); //false
moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '[)'); //true
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '()'); //false
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '(]'); //true
moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', null, '[]'); //true
@Farkal
Copy link
Author

Farkal commented Oct 16, 2018

Exemple of function:

function _isBetween (date, dateStart, dateEnd, includeStart = false, includeEnd = false) {
  let result = date.isAfter(dateStart) && date.isBefore(dateEnd);
  if (!result && includeStart) result = date.isSame(dateStart);
  if (!result && includeEnd) result = date.isSame(dateEnd);
  return result;
}

@iamkun
Copy link
Owner

iamkun commented Feb 11, 2019

added in #464

@iamkun iamkun closed this as completed Feb 11, 2019
@iamkun
Copy link
Owner

iamkun commented Feb 19, 2020

Update: Support isBetween() API inclusivity https://day.js.org/docs/en/query/is-between

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants