Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Business days calculation

 
Apu Nahasapeemapetilon
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a need for calculating the number of business days from a given date. Wait, that is ambiguous.
I pass you a date and an offset in days, you return the date that is the number of business days equal to the offset from the date passed. (example, date = friday 1/1/00 offset = 2, method would return Tuesday 1/5/00)
I can easily do this, but am wondering why they deprecated the date object with the calendar object and don't offer any business days functionality for the new calendar object? (isBusinessDay()???) Don't even get me started on holidays....
Anybody do this already?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry no one else has replied - I don't know of anyplace that has this functionality already. As you say, it's not too difficult to write for yourself unless you want to include holidays as non-business days. The list of which holidays to include, and when they fall, will probably be location-specific and rather complicated to maintain. I suspect that you'll want to develop a method like
<code><pre> public boolean isBusinessDay(Date day) { ... }</pre></code>
which can tell you if a given date is considered a business day or not; you'll then have to call this function on each day in succession after the start date until you've found the required number of business days. The reason for this is that there are enough odd holidays whose dates change from year to year, that you really need to look up each day individually to see if it's a holiday. If all you wanted to do was skip the Saturdays and Sundays, there would be other ways to go about it, but once you include holidays there really won't be any shortcuts, I think. For holiday calculation, I think the easiest thing is to require someone to maintain a file which lists all the holidays within a given time period. Each time isBusinessDay() is called return false if it's a Saturday, Sunday, or is listed on the holiday list; true otherwise.
It does seem as though someone somewhere has probably developed something to do this, at least for "standard" US holidays (if that's where you are), but I have no idea where to find it.
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apu,
There is a java tip that discusses holidays (a trival activity to add a business day method).
www.javaworld.com
Scroll down to resources, then click on tips index link
from index scroll down to tip # 44.
http://www.javaworld.com/javaworld/javatips/jw-javatip44.html
(full url)

but as a major aside, just what is a business day. i have created a lot of these functions over the years and it seems to have a different answer for every company i work for, consult to or teach.
hope this helps
steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic