• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Business days calculation

Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Posts: 612
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a java tip that discusses holidays (a trival activity to add a business day method).
Scroll down to resources, then click on tips index link
from index scroll down to tip # 44.
(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
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic