Scott asked:
>> >* Here is DateTime 1
>> >* Here is DateTime 2
>> >* Here is the working week (Mon-Fri, 9-5) (or whatever we define)
>> >* Tell me the working hours between DateTime 1 and DateTime 2

> Rick Measham wrote:
>> G'day DateTimers,
>> Any clues on why the intersections don't create properly?

Flavio S. Glock replied:
> Rick:
> Creating a complex recurrence function is hard.
> It is much easier to use DT::Event::Recurrence:

Thanks Flavio,

Is anyone working on business modules yet? I figure your code would be a
great place to start:

$working_hours = new DateTime::Business::Week(
        days  => [1 .. 5],
        start => {hour => 9,  minute => 0},
        end   => {hour => 17, minute => 30}
);

and, for those with more complex weeks:

$working_hours = new DateTime::Business::Week(
        {
                days  => [3 .. 5],
                start => {hour => 9,  minute => 0},
                end   => {hour => 17, minute => 30}
        },
        {
                days  => 6,
                start => {hour => 9,  minute => 0},
                end   => {hour => 17, minute => 00}
        },
        {
                days  => 7,
                start => {hour => 10,  minute => 30},
                end   => {hour => 16, minute => 30}
        },
);

Basically Business::Week->new would return an infinite spanset for all
working hours. 

It could then be extended to allow for spans so we can include historical
data:

$working_hours->history(
        span => $span,
        week => $business_week
);

And such things as a finite span:

$working_hours->set_start($dt1); # start of employment
$working_hours->set_end($dt2);   # sacked!

Then we could create other spansets for employee related information

$working_hours->public_holiday( $recurrence ); # or $span or $spanset
$working_hours->annual_leave( $span ); # or $spanset
$working_hours->sick_leave( $span ); # or $spanset

With/without parameters the above three functions would return spansets for
the time off work.

Then we can set a project for a particular span:

$working_hours->project( 
        name => 'Project X',
        span => $span, # or $spanset
);
If given a 'name' this method returns spanset for that project.

Now we can get a complete record of activity:

print $working_hours->activity( $datetime );
# Annual Leave   
print $working_hours->activity_span( $datetime )->min->ymd;
# 2003-08-12
print $working_hours->activity_span( $datetime )->max->ymd;
# 2003-08-19

print $working_hours->activity( $datetime2 );
# Project X   

print $working_hours->activity( $out_of_hours_datetime );
# undef

And we need a quick boolean test to see if the person was actually at work
print "Absent" unless $working_hours->at_work;


Comments/Thoughts/...?

Cheers!
Rick


-- 
Obviously the reply-to is a fake. Just change the 'spam-' to 'i' so that the
result sounds like why you go to an optometerist.

Reply via email to