aspose file tools
The moose likes Java in General and the fly likes calculating the number of business minutes in a month Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "calculating the number of business minutes in a month" Watch "calculating the number of business minutes in a month" New topic
Author

calculating the number of business minutes in a month

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
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.


"I'm not back." - Bill Harding, Twister
Steve Fahlbusch
Ranch Hand

Joined: Sep 18, 2000
Posts: 491
    
    2

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

Joined: Jul 22, 2000
Posts: 9033
    
  10
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

Joined: Jan 30, 2000
Posts: 18670
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.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: calculating the number of business minutes in a month
 
Similar Threads
Calendar class
timestamp
Where does the extra day come from in duration calculation?
Business days calculation
Calendar / Date arithmetic