moment-weekday-calc icon indicating copy to clipboard operation
moment-weekday-calc copied to clipboard

Weird wrong calculation for certain date, when start > end date

Open hdoan741 opened this issue 3 years ago • 2 comments

const workdays1 = moment().weekdayCalc('21 Feb 2016', '31 Mar 2016', [1,2,3,4,5]); 
// 29
const workdays2 = moment().weekdayCalc('31 Mar 2016', '21 Feb 2016', [1,2,3,4,5]); 
// 28

There is a bizarre problem where the weekdayCalc is different when the start date & end date is reversed. Specifically, if start > end, some time the result is 1 day short of the correct value.

In the source code, I could see that if start > end, their position are switched. The calculation should have been the same for both. I don't know how this could happen. See the example above.

hdoan741 avatar Feb 13 '22 08:02 hdoan741

@manhhung741 Could you please advice which version do you use? I'm pretty sure it should throw an error if start date is after end date.

andruhon avatar Feb 14 '22 08:02 andruhon

The version I'm using is "moment-weekday-calc": "^1.1.4",

I thought this code would flip start & end date if start > end date

https://github.com/andruhon/moment-weekday-calc/blob/master/src/moment-weekday-calc.js#L202-L207

hdoan-codaio avatar Feb 14 '22 19:02 hdoan-codaio