i'm currently using moment.js library to render dates in real time to my users, but after some tests today, i noticed something really weird, when listing all possible days to the user in Firefox, moment.js fails to add days in the date '2015-09-14'. After searching the developers documentation and the internet, i discovered that you have to pass a ISO8601 valid Date or construct by passing explicit information of the date, but the results continue to confuse me.
Here's some code for understanding:
Working case (creating a moment() instance from current time):
var printVar = moment();
var divInfo = document.getElementById('calendars');
divInfo.innerHTML += "<ul>";
for(var i=0; i<40; i++){
divInfo.innerHTML += "<li> " + printVar.format('DD/MM/YYYY') + " </li>";
printVar = moment(printVar).add(1, 'days');
}
divInfo.innerHTML += "</ul>";
My Result:
- 15/10/2015
- 16/10/2015
- 17/10/2015
- 18/10/2015
- 19/10/2015
- 20/10/2015
Weird case #1 (creating a moment() using time with encoding 'YYYY-MM-DD'):
var printVar = moment('2015-09-14');
var divInfo = document.getElementById('calendars');
divInfo.innerHTML += "<ul>";
for(var i=0; i<40; i++){
divInfo.innerHTML += "<li> " + printVar.format('DD/MM/YYYY') + " </li>";
printVar = moment(printVar).add(1, 'days');
}
divInfo.innerHTML += "</ul>";
My Result:
- 15/10/2015
- 16/10/2015
- 17/10/2015
- 17/10/2015
- 18/10/2015
- 19/10/2015
Weird case #2 (creating a moment() using explicit constructor like moment([2015, 8, 14])) return the same result:
- 15/10/2015
- 16/10/2015
- 17/10/2015
- 17/10/2015
- 18/10/2015
- 19/10/2015
Firefox version: 40.0.3
Thanks for all the Help!



