#!/usr/bin/perl ### # altblue 1999 ### # o reinventare a rotii? ################ use Time::Local; @dates = &get_dates(@ARGV); unless(@dates) { print "bleah. some error occured. bailing out.\n"; } else { print "Date interval contains:\n"; foreach(@dates) { print "\t$_\n"; } } #========================================================================= # usage: # @date = get_dates(start_date [, stop_date [,nice_month]]); # - returns an array with all the dates between start and stop date # - if start is 0, engine assumess the first day of the current year # - if start is 1, engine assumess the first day of the current month # - if stop is undefined, engine assumess today # NOTES: # * Requires Time::Local to work! # * Take care to give valid dates!... there are almost no checkups! # (speed reasons) #---------------------- sub get_dates { my @months = ('January','February','March','April','May','June', 'July','August','September','October','November','December'); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $separator = '-'; if (defined $_[0]) { if($_[0] =~ /^([0-9]{1,2})(.)([0-9]{1,2}).([0-9]{4})$/) { $separator = $2; my $m = $1-1; $m = 11 if $1 > 11 || $1 < 0; $start = timelocal(0,0,0,$3,$m,$4-1900); } elsif ($_[0] == 1) { $start = timelocal(0,0,0,1,$mon,$year); } else { $start = timelocal(0,0,0,1,0,$year); } } else { return ($mon+1).$separator.$mday.$separator.($year+1900); } if($_[1] =~ /^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})$/) { $stop = timelocal(0,0,0,$2,$1-1,$3-1900); } else { $stop = timelocal(0,0,0,$mday,$mon,$year); } my (@dates,$current,@kk); while($start <= $stop) { @kk = localtime($start); if(defined $_[2]) { print "debug\n"; $kk[4] = $months[$kk[4]]; } else { $kk[4]++; $kk[4] = '0'.$kk[4] if $kk[4] < 10; } $kk[3] = '0'.$kk[3] if $kk[3] < 10; $current = $kk[4].$separator.$kk[3].$separator.($kk[5]+1900); push(@dates,$current); $start += 86400; } return @dates; }