File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to calculate Business hours Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to calculate Business hours " Watch "How to calculate Business hours " New topic
Author

How to calculate Business hours

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Hi guys,

I have a Java & SQL web application where a business will enter their business open and closed time for each day of the week (Mon - Sun).

However, I need to display the business hours to the end user.
Example:
Mon - Wed open 8am to 5pm.
Thurs open 8am to 6pm
Fri open 8am to 8pm
Sat & Sun closed

So, my brain has gone dead on trying to figure the best algorithm to dynamicly display business hours including consecutive days.

Can you guys give me suggestions on how to determine business hours using Java or SQL?

Thanks in advance....
Mohan Vinukonda
Ranch Hand

Joined: Jul 28, 2005
Posts: 32
quote
------------------------------------------------------------------
However, I need to display the business hours to the end user.
Example:
Mon - Wed open 8am to 5pm.
Thurs open 8am to 6pm
Fri open 8am to 8pm
Sat & Sun closed
-------------------------------------------------------------------

What exactly you are tring to find out??? would you need to display some data based on business hours or someting different?


-Mohan
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think the challenge is the the Mon-Wed part, no? I used to do a lot of group-break loops like this:

Does that make sense? Can anybody do it in SQL?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Thanks for the suggestion...but still does not answer it. As I loop through the list of days in the week, I need to do the following:

1) keep track of the days that have the same open and close time
2) determine if the days that have the same business hours are consecutive (eg. Mon - Fri, or Fri - Sat)
3) the challenge I'm facing is when there are more than 1 consecutive day sets that have the same business hours (eg: Mon-Thurs 8am - 5pm and Fri-Sun 11am - 11pm)

this seems trivial...but I don't understand why I'm having a hard time to come up with a dynamic algorithm for this....

Pls...heLP
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Try the loop I showed with pencil & paper ...

Mon 8:00 5:00
Tue 9:00 6:00
Wed 9:00 6:00
Thu 8:00 5:00

I think it will report

Mon 8:00 5:00
Tue-Wed 9:00 6:00
Thu 8:00 5:00
[ September 04, 2007: Message edited by: Stan James ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to calculate Business hours