Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix business days counting in before/after methods #235

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

guillaumebihet
Copy link

@guillaumebihet guillaumebihet commented Jan 29, 2025

Reference

Issue 196

Description

Problem:

The counting of business days is inconsistent in before and after methods depending on whether the start date is a workday or not.

When starting on a workday:

> 5.business_days.before(Date.new(2025, 1, 15))
=> Wed, 08 Jan 2025

This only counts 4 workdays (Tue 14, Mon 13, Fri 10, Thu 9), instead of 5.

But when starting on a non-workday:

> 5.business_days.before(Date.new(2025,02,15))
=> Fri, 07 Feb 2025

This correctly counts 5 workdays (Fri 14, Thu 13, Wed 12, Tue 11, Mon 10).

See also #196 (comment) for a more detailed explanation.

Solution:

Move one day first before starting the count:

time -= 1.day  # For before()
# or
time += 1.day  # For after()

This ensures we never count the start date itself, making the behavior consistent in all cases.

Move one day before starting count to ensure consistent behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant