Appendium / objectlabkit

Date Calculators for Business /FX, FX Rate Calculator and Utils
http://objectlabkit.sf.net
Apache License 2.0
68 stars 25 forks source link

Calculate Number of Business Days between Two Dates #8

Open Zeouterlimits opened 9 years ago

Zeouterlimits commented 9 years ago

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 commented 9 years ago

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

If the API takes 2 days:

Probably need more examples, what do you think?

Benoit

Zeouterlimits commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 5 years ago

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 commented 5 years ago

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 notifications@github.com 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 .

benoitx commented 5 years ago

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

Agreed?

benoitx commented 5 years ago

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

Assume that:

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Sure, I'll give it a try.

benoitx commented 5 years ago

A snapshot is available at the repo: https://oss.sonatype.org/content/repositories/snapshots/net/objectlab/kit/objectlab-portfolio/1.4.3-SNAPSHOT/

benoitx commented 4 years ago

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 notifications@github.com 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 .