bokmann / business_time

Support for doing time math in business hours and days
MIT License
1.27k stars 215 forks source link

Business day calculations off when starting with a non-workday #196

Open dsadaka opened 5 years ago

dsadaka commented 5 years ago

Whether I start on a weekend date or I use the holidays feature, if my starting date is a non workday, and I add business_days to it, it will skip to the next day before doing the calculaiton.

Example1 holiday: dt = Date.civil(2019,11,11) Which is veterans day (specified in holdays) 1.business_day.after(dt) will yield Wednesday 11/13/2019 instead of Tuesday

Example2 weekend: dt = Date.civil(2019,11,17)) 1.business_days.after(dt) => Tue, 19 Nov 2019

Is this by design? How do I work around this? Do I need to check the start date for .workday? after the calculation and subtract 1?

rmm5t commented 2 years ago

@dsadaka This is by design.

For example, consider the scenario of asking for 0.business_days.after(dt) on a Sunday:

>> dt = Date.current
=> Sun, 26 Jun 2022
>> 0.business_days.after(dt)
=> Mon, 27 Jun 2022

e.g. It wouldn't make sense to return a non-business day when asking for 0 business days in future.