I wouldn't recommend using the functions directly, as they're not intended for public use or documented and thus could change out from underneath you in a future revision.
Copying them works; as you say, they're short.
Or, using Date::Calc:
use Date::Calc qw(Today_and_Now Add_Delta_YMDHMS Day_of_Week_to_Text M
+onth_to_Text Day_of_Week);
while (<DATA>) {
chomp;
print "$_\n";
print cgitime($_), "\n";
}
sub cgitime {
my $arg = shift;
my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now(1); # retu
+rn 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 defi
+ned $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_t
+o_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
produces:
now
Monday, 24-November-2003 23:26:11 GMT
+10s
Monday, 24-November-2003 23:26:21 GMT
+2w
Monday, 08-December-2003 23:26:11 GMT
-1w
Monday, 17-November-2003 23:26:11 GMT
-10m
Monday, 24-November-2003 23:16:11 GMT
+1M
Wednesday, 24-December-2003 23:26:11 GMT
+10y
Sunday, 24-November-2013 23:26:11 GMT
-1h
Monday, 24-November-2003 22:26:11 GMT
+3d
Thursday, 27-November-2003 23:26:11 GMT
Updated: Oops; 'w' for week isn't valid, and after I went to all the bother of making a special case for it.
|