use Date::Calc qw(Today_and_Now Add_Delta_YMDHMS Day_of_Week_to_Text Month_to_Text Day_of_Week); while () { chomp; print "$_\n"; print cgitime($_), "\n"; } sub cgitime { my $arg = shift; my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now(1); # return in GMT for ($arg) { last if /^now$/; my @units = qw(y M d h m s); # order sensitive my $allowed = join 'w', @units; my ($sign, $num, $unit) = (/^([+-])(\d+)([$allowed])$/); return unless defined $sign and defined $num and $num and defined $unit; $unit = 'd' and $num *= 7 if $unit eq 'w'; my @args = map /$unit/ ? "$sign$num" : 0, @units; ($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec,@args); } return sprintf "%s, %02d-%s-%4d %02d:%02d:%02d GMT", Day_of_Week_to_Text(Day_of_Week($year,$month,$day)), $day, Month_to_\ Text($month), $year, $hour, $min, $sec; } __END__ now +10s +2w -1w -10m +1M +10y -1h +3d