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

range.by('month') excluding last month in range #282

Open
razzp opened this issue Jul 16, 2020 · 3 comments
Open

range.by('month') excluding last month in range #282

razzp opened this issue Jul 16, 2020 · 3 comments

Comments

@razzp
Copy link

razzp commented Jul 16, 2020

I have a date range that starts in June and runs through July and into August. Creating an iterable of months in the range yields only the first two months. August is not included.

Steps to Reproduce

const range = moment.range('2020-06-23', '2020-08-21');
const months = Array.from(range.by('months')).map(date => date.format('MMMM'));
console.log(months);

Expected Behavior

Array [ "June", "July", "August" ]

Current Behavior

Array [ "June", "July" ]


moment.js 2.27.0
moment-range 4.0.2

Unless I'm missing something this seems to be a bug. Explicitly setting { excludeEnd: false } doesn't work either.

@MorenoMdz
Copy link

Same thing is happening when using by "day" it is excluding the last day.

@linxianxi
Copy link

same question

@cyonkee
Copy link

cyonkee commented Jan 12, 2022

I removed the module because of this issue. The following works fine:

private getDateRange(from: Moment, to: Moment): readonly Moment[] {
	const numberOfDays = to.diff(from, 'days') + 1;
	return [...Array(numberOfDays).keys()].map(i => moment(from).add(i, 'days'));
}

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