icambron / twix.js

:hourglass::left_right_arrow: A date range plugin for moment.js
https://isaaccambron.com/twix.js/
MIT License
379 stars 54 forks source link

Bug while iterating weeks between 2 dates #110

Open DheerajKN opened 5 years ago

DheerajKN commented 5 years ago

There is a while Bug I am iterating with weeks between 2 dates and here is the code that I used

var itr = moment.twix(new Date('2018-10-06T00:00:00'),new Date('2018-11-12T00:00:00')).iterate("weeks");
var range=[];
while(itr.hasNext()){
    range.push(itr.next().format("YYYY-M-D"))
}
console.log(range);

Which generates the below result:

"2018-9-30"
"2018-10-7"
"2018-10-14"
"2018-10-21"
"2018-10-28"
"2018-11-4"
"2018-11-11"

When I was requesting for week sequence starting from '6th October' why I am getting results from a week prior.

Expected Result:

"2018-10-6"
"2018-10-12"
"2018-10-19"
"2018-10-26"
"2018-11-1"
"2018-11-8"

How can I resolve this issue??

America-first-melon commented 5 years ago

moment(start).twix(end).toArray("week")