Matthew Persico wrote:
1) Add a convenience method called 'today' to DateTime, which is the
same as Date::Time->now->trunc(to=>day)

Already there ..
$today = DateTime->today();

2) All business dates will have no time component. All decrements and
increments of business dates will be a number of days - I don't think
there is a concept of business weeks or months...

Absolutely disagree on this point. You have to have finer control than days. If a project is going to take 100 man-hours and you have 7 people working on it, you need to be able to do:

$now = DateTime::Calendar::Business->now();

$now->add( hours => 100 / 7 );

print "You're gonna finish at $now.";


Also, you cannnot ignore things like weeks and months. Especially months. From a business POV, in Australia note the following behaviour would be 'correct':

$this_year = DateTime::Calendar::Business::Australia->now->trunc( to => year );

print $this_year->datetime;

# 2004-07-01T00:00:00

In Australia, the tax year start on July 1st and finishes on June 30th and so truncating to year would have to return a July 1st date. In the states I believe it's April 19th or some such.


There's probably hundreds, if not thousands, of different ways of defining business days and so I'd suggest implementing a simple way to localize and cascade your data such as this:

package DateTime::Calendar::Business::Australia;

@ISA = qw/DateTime::Calendar::Business/;

$YEARSTART = { month => 7, day => 1 };

@BUSINESSHOURS = [
        1 => [ {hour => 9}, {hour => 17} ],
        2 => [ {hour => 9}, {hour => 17} ],
        3 => [ {hour => 9}, {hour => 17} ],
        4 => [ {hour => 9}, {hour => 17} ],
        5 => [ {hour => 9}, {hour => 17, minute => 30} ],
        6 => [ {hour => 9}, {hour => 12} ],
        7 => [ ],
];

@PUBLICHOLIDAYS = [
        { month=>1, day=>26 },  #Australia Day
        { month=>4, day=>25 },  #ANZAC Day
        { month=>12, day=>25 }, #Christmas Day
        { DateTime::Event::Easter->new( day=> -2) }, #Good Friday
        { DateTime::Event::Easter->new( day=>  0) }, #Easter Sunday
];

package DateTime::Calendar::Business::MyCompany;

@ISA = qw/DateTime::Calendar::Business::Australia/;

@BUSINESSHOURS = [
        1 => [ {hour => 9}, {hour => 17, minute => 30} ],
        2 => [ {hour => 9}, {hour => 17, minute => 30} ],
        3 => [ {hour => 9}, {hour => 17, minute => 30} ],
        4 => [ {hour => 9}, {hour => 21} ],
        5 => [ {hour => 9}, {hour => 21} ],
        6 => [ {hour => 9}, {hour => 17} ],
        7 => [ {hour =>10}, {hour => 16} ],
];


__END__

Once you have all your definitions in place, then a DateTime::Calendar::Business object should work just like a DateTime object -- you should be able to truncate it, add to it, subtract from it etc. Just have to remember that a day on your calendar is not the same as a day on the gregorian calendar, your days are only 7 or 8 hours each and you weeks are 5 or 6 days long.

Cheers!
Rick Measham

Reply via email to