eduolalo / moment-business-days

This is a momentJS plugin that allows you to use only business days (Monday to Friday)
MIT License
240 stars 67 forks source link

adding 2 weeks doesn't take business days into account? #71

Open sam26880 opened 5 years ago

sam26880 commented 5 years ago

I have this code which returns 5/7/2019 when adding 2 weeks to today's date which is 4/23/2019 I have set the setting that says that Thursday is NOT a working day. So it should be skipping Thursday as well as weekend in this calculation. Am I correct?

Here's the code I have this.task.FollowupDate = moment().businessAdd(2, 'weeks').format('MM/DD/YYYY');

it does seem to work correctly when I add 10 DAYS. It correctly skips Thursdays and Weekends.

So does this not work with WEEKS? or is that how it's supposed to work?

mcdado commented 5 years ago

Yeah… you're onto something: https://github.com/kalmecak/moment-business-days/blob/accaa23c28229d3ba6a2627a8eb30a364280d4ee/index.js#L95

At the moment this is how the plugin works: it adds takes 2 weeks, it iterates adding or subtracting one week (depending on which method is called), depleting the week counter only if the resulting day is a business day. This is a logic that works with days, but not weeks or months or years… my guess to how to fix this is "converting" weeks to days and using the same logic.