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

isBetween inclusivity solved #429

Closed
Noeldeveloper opened this issue Dec 14, 2018 · 5 comments
Closed

isBetween inclusivity solved #429

Noeldeveloper opened this issue Dec 14, 2018 · 5 comments

Comments

@Noeldeveloper
Copy link

Noeldeveloper commented Dec 14, 2018

I leave my two cents for isBetween functionality.

That's an approach of moment.js way to treat inclusivity, it can be added to isBetween plugin:

image

code:

export type DayjsInclusivity = '()' | '[)' | '(]' | '[]';

isBetween(date: Dayjs, dateStart: Dayjs, dateEnd: Dayjs, precision?: UnitType, inclusivity?: DayjsInclusivity ) {
let result = dayjs(date).isAfter(dateStart, precision) && dayjs(date).isBefore(dateEnd, precision);
if (!result && (inclusivity || inclusivity !== '()')) {
if (inclusivity === '[)') {
result = dayjs(date).isSame(dateStart, precision);
} else if (inclusivity === '(]') {
result = dayjs(date).isSame(dateEnd, precision);
} else {
result = dayjs(date).isSame(dateStart, precision) && dayjs(date).isSame(dateEnd, precision);
}
}
return result;
}

@naulacambra
Copy link
Contributor

Maybe you could create a PR with the changes?

@waseemahmad31
Copy link
Contributor

Can I submit a pull request for this?

@naulacambra
Copy link
Contributor

@waseemahmad31 sure 😀

@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 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

4 participants