Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to calculate Business hours

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic