objectlabkit
objectlabkit copied to clipboard
Calculate Number of Business Days between Two Dates
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
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
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.
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.
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]
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
Hi
I'd welcome a patch as I'm very busy at the moment... many thanks. Benoit
On Tue, 14 May 2019 at 23:54, ailes17 [email protected] wrote:
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
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Appendium/objectlabkit/issues/8?email_source=notifications&email_token=AAB542NK6F7ITJFEKYLAR3LPVM7L5A5CNFSM4AWCFCJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVNAXFQ#issuecomment-492440470, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB542OQHFLHSLP74F53UXLPVM7L5ANCNFSM4AWCFCJQ .
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?
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? |
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
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.
Sure, I'll give it a try.
A snapshot is available at the repo: https://oss.sonatype.org/content/repositories/snapshots/net/objectlab/kit/objectlab-portfolio/1.4.3-SNAPSHOT/
Hello
Have you had a chance to try it? Is it working for you now?
Many thanks
Benoit
On Wed, 22 May 2019 at 23:35, ailes17 [email protected] wrote:
Sure, I'll give it a try.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Appendium/objectlabkit/issues/8?email_source=notifications&email_token=AAB542IOQRYPXTXQDRAFUK3PWXDC3A5CNFSM4AWCFCJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWAROJY#issuecomment-494999335, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB542JTXEI732ILXVCH57DPWXDC3ANCNFSM4AWCFCJQ .