[Israel.pm] Calendar mangment

Gabor Szabo gabor at perl.org.il
Sun Oct 24 22:12:20 PDT 2004


On Sun, 24 Oct 2004, Sagiv Barhoom wrote:

> hi all,
> I'm trying to create an application dealing with calendar.
> I need a way to convert range of dates to array of (date|day)
> for example given
> $input= 30/11/2004-04/11/2004
> the result should be:
> @output=(
> 		30/11/2004|Saturday,
> 		31/11/2004|Sunday,
> 		01/12/2004|Monday.
> 		02/12/2004|Tuesday,
> 		03/12/2004|Wednesday,
> 		04/12/2004|Thursday
> 		)
>
> Has anyone  programmed  something like  that - can you give me a clue?
> I took a look in cpan but there are 282 modules working with calendar, just too many :-)
> Sagiv

Pick any one of those :)

Or here is an *untested* example without them :)


use POSIX qw(mktime strftime);

my $input= 30/11/2004-04/11/2004
my @output;

my ($start_day, $start_month, $start_year,
      $end_day,   $end_month,   $end_year) = split /[\/-]/, $input;

my $date = mktime(0,0,12,$start_day, $start_month-1, $start_year-1900);
my $end  = mktime(0,0,12,  $end_day,   $end_month-1,   $end_year-1900);


while ($date <= $end) {
   push @output, strftime("%d/%m/%Y|%A" , localtime $date);
   $date += 60*60*24;
}


I am sure this suffers when changing Day Light Saving Time.

Gabor




More information about the Perl mailing list