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

Question about start date later than end date #268

Closed
zh3ngyuan opened this issue Oct 14, 2019 · 2 comments
Closed

Question about start date later than end date #268

zh3ngyuan opened this issue Oct 14, 2019 · 2 comments

Comments

@zh3ngyuan
Copy link

zh3ngyuan commented Oct 14, 2019

version: v4.0.2
when I run the following script:

var start = moment('10/11/2019', 'MM/DD/YYYY');
var end = moment('10/05/2019', 'MM/DD/YYYY');
Array.from(moment.range(start, end).by('day')).map(function(date) {
    return date.format()
});

I got the output like this

// [
//     "2019-10-11T00:00:00-07:00", 
//     "2019-10-12T00:00:00-07:00",
//     "2019-10-13T00:00:00-07:00", 
//     "2019-10-14T00:00:00-07:00", 
//     "2019-10-15T00:00:00-07:00", 
//     "2019-10-16T00:00:00-07:00", 
//     "2019-10-17T00:00:00-07:00"
// ]

Apparently, the result is incorret, and what I expected should be [] or [endDate, ... , startDate]

I was wondering if there is any validation for the case that start date is later than the end date? otherwise, I need to validate it by myself before generate the range.

@TristanJM
Copy link
Contributor

Hey, we've left validating the order of the input dates to the user. You're correct in that you should validate this first and ensure the end moment comes after the start of the range :)

FYI We've raised #201 and are considering automatically sorting the order of inputs

@TristanJM
Copy link
Contributor

Please feel free to reopen the issue if you spot some weird behaviour! 😃

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