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

Array.from(range.by('month')) skips a last month #288

Open
ka-terok opened this issue Feb 4, 2021 · 1 comment
Open

Array.from(range.by('month')) skips a last month #288

ka-terok opened this issue Feb 4, 2021 · 1 comment

Comments

@ka-terok
Copy link

ka-terok commented Feb 4, 2021

Hello!

  1. I have
    start = 04.02.2020
    end = 1.03.2020 or 2.03.2020 or 3.03.2020

const range = moment.range(start, end)
When I do console.log(range) - it's ok

But then
let months = Array.from(range.by('months')).map(m => m.format('MMM'))
let days = Array.from(range.by('days')).map(m => m.format('DD MMM YYYY'))

at the end:
months = ['feb.'] - wrong
days = [04.02.2020 , ....] - it's ok

Even if I do
let months = Array.from(range.by('months', {excludeEnd: false})).map(m => m.format('MMM'))
at the end: months = ['feb.'] - wrong

But if
2)
start = 01.02.2020
end = 1.03.2020 or 2.03.2020 or 3.03.2020
at the end: months = ['feb.', 'mart'] - ok

What should I do to make 1 work?
It's my false or no?

@sota2d
Copy link

sota2d commented Jul 28, 2021

Having the same issue. Was trying to get an array of months between 2 dates and failed.

                const start = '2020-07-31';
                const end =  '2021-07-28';
                const range = moment.range(start, end)
                const arrayOfDates = Array.from(range.by('month'))
                const arr = arrayOfDates.map(el => {
                   return el.format("MMM/YYYY");
             }

returns:
["Jul/2020", "Aug/2020", "Sep/2020", "Oct/2020", "Nov/2020", "Dec/2020", "Jan/2021", "Feb/2021", "Mar/2021", "Apr/2021", "May/2021", "Jun/2021"]

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