• Post Reply Bookmark Topic Watch Topic
  • New Topic

calculating the number of business minutes in a month  RSS feed

 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!