Question

When creating a moment date object using the following settings:

var date = moment({
    year:   2014,
    month:  2,
    day:    17,
    hour:   9,
    minute: 60
});
date.isValid(); // false

Mon Mar 17 2014 10:00:00 GMT+0100 (Romance Standard Time)

The output is correct but when I try to validate this date, it is incorrect. I think it's because the mintues are greater than 60. Normally this would not be a problem but i'm using Twix to create ranges and due to this problem i'm getting invalid dates. Is there any way to fix this issue?

Was it helpful?

Solution

You may use the native Date constructor to deal with overflows for you :

var date = moment(new Date(2014,2,17,9,60));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top