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

Dear Monks,

I have mentioned the below code i tried using Date::Calc module. I have to get the input From date, To date and Hours from the user. I have to distribute the Hours with in the From date and To date i have given. Allocate 8hrs. for each date. Remaining hrs. to be mentioned at last as remainder. I have omit the holidays as mentioned in Date::Calc holidays. Please give me any idea or code.

Thanks in advance.

#!/usr/bin/perl #INPUT : 17 December 2001 to 16 June 2002 use strict; use Date::Calc qw( :all ); my ($fdate,$tdate,$day,$month,$year,$tday,$tmonth,$tyear,$i,$j,$hour); my (@start,@stop,@date); print "Enter the From Date: "; chomp($fdate = <STDIN>); print "Enter the To Date: "; chomp($tdate = <STDIN>); print "Enter the Total hours: "; chomp($hour = <STDIN>); ($day,$month,$year)=split(" ", $fdate); ($tday,$tmonth,$tyear)=split(" ", $tdate); $month = Decode_Month($month); $tmonth = Decode_Month($tmonth); if (Date_to_Days($year,$month,$day) > Date_to_Days($tyear,$tmonth,$tday)) { print "\nThe From date should less than To Date\n"; } else { @start = ($year,$month,$day); @stop = ($tyear,$tmonth,$tday); $j = Delta_Days(@start,@stop); for ( $i = 0; $i <= $j; $i++ ) { @date = Add_Delta_Days(@start,$i); printf("%4d/%02d/%02d\n", @date); } }

Replies are listed 'Best First'.
Re: How to distribute time using Date::Calc module?
by Jaap (Curate) on May 04, 2005 at 09:17 UTC
    First you have to create a 3D array @holiday with the dates of the holidays set to 1, like so:
    ### New years day $holiday[2005][1][1] = 1;
    Fist add the fixed dates like newyearsday, then add the Easter-depending days using Easter_Sunday($year); and calculate the easter-depending days from there as described on Date::Calc.

    Now loop through the days starting at startdate, incement by one and see if the date is not Saturday or Sunday and not a holiday.