Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Work Roster Calcuation

by Smaug (Pilgrim)
on Jun 02, 2008 at 09:16 UTC ( [id://689657] : perlquestion . print w/replies, xml ) Need Help??

Smaug has asked for the wisdom of the Perl Monks concerning the following question:


I have been out of this for some time and I'm now trying yet again to brush off the rust and get back to some coding, so please be patient.....
I need to be able to do some date arithmetic for a work roster. For this I would like to convert a series of dates into Unix Time so that I can easily add and subtract. The problem is the format I'm given the information as shown below:
Mon - Fri { 07:00 - 18:00 } Sat { 08:00 - 16:00 } Sun { 09:00 - 13:00 } 08/04/27 {} 08/05/01 {} 08/06/16 {} 08/08/09 {} 08/09/24 {} 08/12/16 {} 08/12/25 {} 08/12/26 {} 09/01/01 {}

What this means is all the hours from Monday to Friday between 07:00 and 18:00. (note: it could also read 7:00 AM - 6:00 PM)
Dates without times specified are holidays where no work is done.

So effectively I need to calculate the amount of working hours taken to complete a task which may take 3 weeks, but only include or exclude the hours as shown above.
I have looked at Date::Manip, but it has numerous warnings stating, "be sure that you REALLY need to use this module".

Should I be looking at something else?
Peddle faster monkeys!! I need more power!!

Replies are listed 'Best First'.
Re: Work Roster Calcuation
by Anonymous Monk on Jun 02, 2008 at 10:54 UTC
Re: Work Roster Calcuation
by pc88mxer (Vicar) on Jun 02, 2008 at 14:50 UTC
    One word of advice -- when I first started to use DateTime I was confused by the fact that the difference of two DateTime objects was not directly convertible into a number of seconds.

    What you'll probably want to do is use the ->utc_rd_as_seconds method to first convert the DateTime objects to seconds and then perform the subtraction. Alternatively, subtract_datetime_absolute might work, too, although the former method also ignores leap seconds which may be helpful.