## If you want a convenient function to generate expiration dates for 
## year-long cookies, you might wish to add this to the CGI function library

#####################################################################
# return the time exactly one year from now
# the returned time is formatted exactly as required when setting cookies
## no Parameters
#####################################################################
sub one_year_from_now {
	
my @days = ("Sun","Mon","Tues","Wed","Thu","Fri","Sat");
my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

#gmtime returns like localtime but in GMT
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime;

$year+=1900; #current year

#augment week day by 1 to reflect the next year 
if($wday<6){
	$wday++;
}
else {
	$wday=0;
}

# if it's a leap year, augment week day by an extra 1 for any month after Feb
# day of month, mday, stays the same unless its leap year in which case Feb 29 becomes 28


if(($year % 4) == 0) { #leap year
	if($mon>1) {
		if($wday < 6){
			$wday++;
		}
		else {
			$wday=0;
		}
	}
	if(($mon == 1)&&($mday == 29)) {
		$mday=28;
	}
}

$year++;  #add 1 to the year

return "$days[$wday], $mday-$months[$mon]-$year $hour:$min:$sec GMT";
}
