• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Calculating Time - HELP

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to calculate a new date using an hour value eg:
Date : 23 March 2005 14:00 pm
Hours to be added: 12
Working hours : 8am - 5 pm

I need to calculate a new date/time using the working hours, so that the added time falls within those working hours.

Thanx...
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which result do you want from your calculation? Let's start with some code
that just add 12 hours to a the given date.

On my machine this code outputs:
Wed Mar 23 14:00:00 CET 2005
Thu Mar 24 02:00:00 CET 2005

This is obviously not in your required time span. If the code above doesn't
help you solve your problem, maybe you could show some exxamples of how the
calculation should work.
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at Calendar. You should be able to work out what methods you need to use.
 
Naadir Peterson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been through the Calendar class, Basically it's easy to just add time to a given date. I need to be able to calculate - say - 12 hours from a given date to incorporate the buisiness hours. If the buisiness' hours are from 8am - 5pm, and 12 hours have to be added from, say 2pm, normally the result would be 2am the following morning, but, the buissiness won't be open then. So 12 working hours from 2pm should be 5pm the following day OR 8am the day after that. I also have to incorporate weekends and public holidays, if the buisiness is closed over these periods.

Hope you'll be able to help me with this.

Cheers...
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I understand what you are trying to achieve now. I'm a bit busy, but how about the following (rough!) pseudo-code:


[ March 23, 2005: Message edited by: Horatio Westock ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic