Re: RFC: API for DateTime::Business:Week (was Re: Time Delta)

2003-10-03 Thread Dave Rolsky
On Thu, 2 Oct 2003, RIck Measham wrote:

 $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}
 },
 );

This all looks reasonable.

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

Actually, it should probably be something that _contains_ a span set.

 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!

In this case I think we might want to create a new object, something like:

 my $finite_working_hours =
 $working_hours-finite_chunk( start = $dt1, end = $dt2 );

 Then we could create other spansets for employee related information

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

I see us needing a couple things:

- Recording the fact that certain days are special non-work days.  This
includes both public holidays, company holidays, one shot things like
fumigating the building, etc.  We not only want to record when these
are, but their names (Christmas, Company Founder's B-Day, Fumigation
Day, etc.) and possibly other arbitrary data associated with them.

- Partial work days, which could again be a recurrence or a one-shot deal.
These need a name and a start/end time of day.

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

This seems like it belongs in a different module.

 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.

ditto

 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

ditto again.

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

ditto

 Comments/Thoughts/...?

I think you're mixing two sets of functionality.

The first thing we need is a business calendar module that lets us
define standard work days/hours, days off, and partial days.

It should also be able to do calculations like, tell us how many business
days occur between two dates, how many business hours/minutes occur
between two datetimes, and generally let us do business datetime math.

Then we can use that module in another module that implements the
per-employee stuff you're interested in.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: RFC: API for DateTime::Business:Week (was Re: Time Delta)

2003-10-03 Thread Bruce Van Allen
On 2003-10-03 Dave Rolsky wrote:
I see us needing a couple things: - Recording the fact that certain
days are special non-work days.  This includes both public holidays,
company holidays, one shot things like fumigating the building, etc.

 We not only want to record when these are, but their names
(Christmas, Company Founder's B-Day, Fumigation Day, etc.) and
possibly other arbitrary data associated with them.

But this should really be kept to a minimum imo, perhaps just one
additional field for a key to look up the associated data somewhere
else. Individual days might collect several layers of special
information. And whatever approach is used, we need to be able to look
things up both ways, i.e., by the date and by the special datum. Otherwise Fumigation 
Day could get scheduled for Founder's B-Day.

In some of my production calendars, each day has 30 or 40 pieces of
associated information, so I use date methods to derive the set of
dates, then create a table -- in memory or database -- with the dates
as primary keys. When the layout program calls for a date, it gets an
object with all that date's info plus self-awareness of its place in
the set. From this perspective, I wouldn't need DateTime::Business to do much besides 
provide the sets or spans, plus the math.

I suppose DT::Biz could provide an API for populating the individual date objects, 
which would then inherit DT::Biz math etc methods; maybe this is what you meant. My 
caution is just to keep in mind that the associated data can multiply, and a structure 
that incorporates the associated data for a whole set of dates/times could get large. 

Dave also said in response to some advance thinking by Rick:
The first thing we need is a business calendar module that lets us
define standard work days/hours, days off, and partial days.

It should also be able to do calculations like, tell us how many
business days occur between two dates, how many business hours/minutes
occur between two datetimes, and generally let us do business
datetime math.

Then we can use that module in another module that implements the
per-employee stuff you're interested in.

Dave++

And Flavio said in anther message:
How about trying to figure out a rough DateTime::Business::* directory
structure? It would also help other authors to find out where to put
their modules.

Flavio++


  - Bruce

__bruce__van_allen__santa_cruz__ca__


RFC: API for DateTime::Business:Week (was Re: Time Delta)

2003-10-02 Thread RIck Measham
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.