jamesplease / moment-business

Utilities for work days in Moment. (Western workweeks only.)
MIT License
100 stars 27 forks source link

Calculation problem if the endDate is weekend #37

Closed acywu closed 8 years ago

acywu commented 8 years ago

When using the weekDays function,

The result may + 1 day when the startMoment and endMoment are both weekend AND when the endMoment is weekend.

Here are some testing results:

console.log(momentBusiness.weekDays(moment('08-05-2016','DD-MM-YYYY'),moment('15-05-2016','DD-MM-YYYY'))); // Actual Result = 5, Expected Result = 4

console.log(momentBusiness.weekDays(moment('09-05-2016','DD-MM-YYYY'),moment('14-05-2016','DD-MM-YYYY'))) // Actual Result = 5, Expected Result = 4

console.log(momentBusiness.weekDays(moment('07-05-2016','DD-MM-YYYY'),moment('13-05-2016','DD-MM-YYYY'))) // Actual Result = 4, Expected Result = 4 <-- This is correct

jamesplease commented 8 years ago

I'll take a look either tonight or tomorrow morning. Is this also affecting v2? Surprised the tests didn't catch this 😮

jamesplease commented 8 years ago

@alexcywu all of those examples you posted seem correct to me.

  1. May 8th - May 15th This is Sunday to Sunday, so 7 days total with the inclusive start, exclusive end algorithm used in this lib. The first day is Sunday, which doesn't count. The last day is Saturday, which also doesn't count. 7-2 = 5.
  2. May 9th - May 14th This removes the end points from the previous example. The result is the same, as the end points were weekends.
  3. this one is also right.
jamesplease commented 8 years ago

Gonna close 'cause these calculations seem correct. Lmk if there are other date ranges you want me to check out @alexcywu !