Help coderanch get a
new server
by contributing to the fundraiser
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 ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# calculating the number of business minutes in a month

Sheriff
Posts: 9109
12
• Number of slices to send:
Optional 'thank-you' note:
If the business is open from 8:00 am to 5:00 pm Monday through Friday, is there a simple way to calculate the number of business minutes in February, 2005, and in July, 2006, and the months between. Not only are the number of days different, but the number of business days are different from month to month as different days fall on the weekend.

Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:
A simple way? Well, um, maybe, sorta. I would hope that "business minutes" are just business days times 480 (8 * 60). Unless there's some way to have fractional business minutes. Do you need to worry only about whole days, or partial days as well? (E.g. start or end times in between 8 AM and 5 PM). What about holidays? Is there a list of those weekdays which Company X considers to be official holidays? Or are all weekdays considered business days?

Ignoring holidays, I'd start by finding the total number of days between the two dates. You may find calendar.get(DAY_IN_YEAR) and calendar.getMaximum(DAY_IN_YEAR) useful for this. Divide by seven (rounding down as normal) to get the number of full weeks in this period (five business days each), and compare calendar.get(DAY_IN_WEEK) to figure out the remaining differences. If there are additional weekday holidays, you'll need to find out how many are between the start and end dates. That's just a rough sketch, but the details are dependent on additional business rules, I think.

Bartender
Posts: 612
7
• Number of slices to send:
Optional 'thank-you' note:
Marylin,

Everytime I have had to face this requirement in the past, not only did they want the information for 'normal' time, but also other shifts and they always wanted to factor in business holidays - and they would play around with day shifting (ie: 1/31 is a monday so it belongs to feb).

The method I have always relied on is a simple list of days (in this case holidays) the shift rules - I would encapsulate these all within a common business date class(es).

I'll see if I have any hanging around on my old workstations.

Marilyn de Queiroz
Sheriff
Posts: 9109
12
• Number of slices to send:
Optional 'thank-you' note:
The calculations also need to work for schedules like:
06:00 - 18:00 M-F
09:00 - 15:00 Sat
09:00 - 12:00 Sun
(with holidays)

and

24 x 7 (no holidays)

and

07:00 - 19:00 Sunday only
(with holidays)

and

06:00 - 18:00 M-F
07:00 - 16:00 Sat
(with holidays)

no fractional minutes just a list/map of total business minutes per month per business (minus holiday minutes when applicable) for each month over a period of about 15 months.

Jim Yingst
Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:
Well, sounds complicated. I would imagine most of the work here will be in figuring out how the schedules and lists of holidays should be passed into your program. You've got a lot of different options floating around here.

With the holidays and any other "special" days you need to deal with, I'd probably put them into a TreeMap where the key is the date, and the value is some object collecting any other info you may need (name of holiday, special rules). Then you can look up all the dates in a certain range, and loop through them to figure out how they affect your total minutes between the two dates.

 It was the best of times. It was the worst of times. It was a tiny ad. We need your help - Coderanch server fundraiser https://coderanch.com/t/782867/Coderanch-server-fundraiser