2

I need the workingday-difference between two dates.

It is easy, to

  • get the difference between two dates
  • get the difference of weekdays between two dates
  • get the workingday difference between two dates for a culture where you know the federal holidays.

But I'm wondering, if there is a method to get this difference in a generic way for any culture?

i.e. in the US, the 4th of july is a federal holiday. So - for Users from the US, the following calculation should apply:

//Assuming:
// 3rd July = Monday
// 4th July = Tuesday
// 5th July = Wednesday

workingDayDiff("03 July", "05 July", Locale.US) //2
workingDayDiff("03 July", "05 July", Locale.Germany) //3

While, around a german federal holidy, i.e. the 3th october:

//Assuming:
// 3rd Oct = Monday
// 4th Oct = Tuesday
// 5th Oct = Wednesday

workingDayDiff("03 Oct", "05 Oct", Locale.US) //3
workingDayDiff("03 Oct", "05 Oct", Locale.Germany) //2

If you know any libraries that work, I'm open for it. (I cannot lookup federal holidays for every possible country and store them somewhere...)

it wouldn't matter if start / Enddate is in- or exclusive, as this can be easily changed by using "+/- 1 day" on the dates.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
dognose
  • 20,360
  • 9
  • 61
  • 107
  • I don't know of any libraries. I'd use an interface WorkingDay { boolean isWorkingDay(Date d); } and provide implementation for each Locale you wish to support, this will allow you to deal with odd rules for Easter bank holidays in the UK etc. this might help: http://www.javaworld.com/article/2077543/learn-java/java-tip-44--calculating-holidays-and-their-observances.html – Adam Dec 03 '14 at 11:52
  • @Adam Something like this I'm doing so far. The point is that I now need this for every country - And I don't want to spend the next 12 Months on doing "federal holiday research" - I don't even know all available Country names worldwide :-) – dognose Dec 03 '14 at 11:54
  • Have a look at this answer... http://stackoverflow.com/a/3388790/898289 – Adam Dec 03 '14 at 11:57

0 Answers0