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

Calculate Number of Business Days between Two Dates #8

Open
Zeouterlimits opened this issue Oct 20, 2014 · 13 comments
Open

Calculate Number of Business Days between Two Dates #8

Zeouterlimits opened this issue Oct 20, 2014 · 13 comments
Assignees
Milestone

Comments

@Zeouterlimits
Copy link

It would be very useful if one could query their DateCalculator and ask it for the number of business days that occur between two dates, obeying the calendar rules that the developer has built into their instance of DateCalculator.

Similar to the code found here:
http://stackoverflow.com/questions/4600034/calculate-number-of-weekdays-between-two-dates-in-java

@benoitx
Copy link
Contributor

benoitx commented Oct 26, 2014

Hi
Thanks for the suggestion. What would you say that the spec should be?

If the API takes 2 days:

  • A->B where B =A+1 and B is holiday, should we return 0? or 1 for A?

Probably need more examples, what do you think?

Benoit

@Zeouterlimits
Copy link
Author

Good question.
This is where a seconds perspective on the business time difference makes sense.

You'd know better how ye view rounding up / down, but to take it as how many business days between 12:00am on A to 12:00am on B, I would see that returning 1.

@benoitx
Copy link
Contributor

benoitx commented Oct 27, 2014

My thoughts were only to deal with dates avoiding the time issues: LocalDate, Date, Calendar and JDK8 LocalDate.

The semantics are not that clear: getNumberOfBusinessDaysBetween(d1, d2);

I'll have a look at what JODA does for something similar (but not taking into weekends/holidays) and then eliminate BOTH d1 and d2 if they are holidays.

Thinking about this, it might be easiest to loop between the dates...unless the holidays are sorted internally. Never mind...that is implementation details.

You'll have to give me a bit of time for this, very busy with business.

@Zeouterlimits
Copy link
Author

Oh I am not in a rush for it at all, I'm using a variant of the code I posted in the StackOverflow link.
I thought it would make sense in ObjectKit as I use it as part of the same area of business time calculations.

[I totally get the desire to avoid the JODA/java.util.date mess, your work is great :-D]

@ailes17
Copy link

ailes17 commented May 14, 2019

Hello,

I know this thread is 5 years old but I was wondering if there is any update on this ?
Having the business days number between two dates (applying on them the holidays list) might come very handy.

Thank you

@benoitx
Copy link
Contributor

benoitx commented May 17, 2019 via email

@benoitx
Copy link
Contributor

benoitx commented May 19, 2019

let's come up with a spec:
int x = getNumberOfBusinessDaysBetween(d1,d2);

  • If no weekend or holidays: d1+x = d2 (Jan 2 + 3 = Jan 5)
  • if d1 or d2 are holidays they are not counted but the calendar does NOT move (e.g. backward with some setups). We would do a straight d2-d1-weekends-holidays [d1,d2]

Agreed?

@benoitx
Copy link
Contributor

benoitx commented May 19, 2019

ok, I need your help. What do you think the results should be?

Assume that:

  • 2006-01-01 is a holiday
  • normal weekends
d1 d2 diff
null null 0
x null 0
null x 0
2006-01-01 2006-01-01 0
2006-01-02 2006-01-02 0
2006-01-01 2006-01-02 0?
2006-01-02 2006-01-03 1
2006-01-01 2006-01-07 4?5?
2006-01-01 2006-01-10 6
2005-12-31 2006-01-01 1?
2005-12-31 2006-01-02 1?

@ailes17
Copy link

ailes17 commented May 19, 2019

Hello Benoit,

Sorry I just saw your messages.
We should have a consistent result with the actual code.
What I mean by this is :
We have today: Date1.moveByDays(X) = Date2
What's needed: Diff(Date2, Date1) = X
(The X between the two equations above should always be the same in all the scenarios)

We use your framework in our code and this reverse engineer calculation would be more than welcome.

Thank you

@benoitx
Copy link
Contributor

benoitx commented May 21, 2019

Excellent idea and it kind of solve some issues when you need a handler to know if you should move backward or forward. If I do a snapshot release, would you be willing to test it? Thanks.

@ailes17
Copy link

ailes17 commented May 22, 2019

Sure,
I'll give it a try.

@benoitx benoitx self-assigned this May 27, 2019
@benoitx benoitx added this to the 1.4.3 milestone May 27, 2019
benoitx added a commit that referenced this issue May 27, 2019
issue #8 First cut at the getNumberOfBusinessDaysBetween method.
@benoitx
Copy link
Contributor

benoitx commented May 27, 2019

@benoitx
Copy link
Contributor

benoitx commented Jul 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants