#!/usr/bin/perl use warnings; use strict; use Time::Local; # Get timestamp input from user print "Enter a timestamp in mm/dd/yyyy hh:mm:ss format: "; chomp(my $stamp = ); # Split out various fields for timelocal my($date, $time) = split / /, $stamp; my($month, $day, $year) = split /\//, $date; my($hour, $minute, $second) = split /:/, $time; # Both timelocal and localtime understand month as in 0 - 11 range $month -= 1; # Get time value in seconds since Epoch with timelocal my $now = timelocal($second,$minute,$hour,$day,$month,$year); # Add padding (this will become interactive) my $paddednow = $now + 300; # Get sensible timestamp back out with localtime my $answer = localtime($paddednow); # Convert result to array for laborious processing of fields my @Answer = split //, $answer; my $Amon = $Answer[4].$Answer[5].$Answer[6]; my $Aday = $Answer[8].$Answer[9]; my $Atime = $Answer[11].$Answer[12].$Answer[13].$Answer[14].$Answer[15].$Answer[16].$Answer[17].$Answer[18]; my $Ayear = $Answer[20].$Answer[21].$Answer[22].$Answer[23]; # Declare hash for conversion of monthname values my %monthy = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12" ); # Handle leading zero issue with day of month my %daything = ( " 1" => "01", " 2" => "02", " 3" => "03", " 4" => "04", " 5" => "05", " 6" => "06", " 7" => "07", " 8" => "08", " 9" => "09" ); my $Amonth = $monthy{$Amon}; my $Arealday; if ($Aday < 10) { $Arealday = $daything{$Aday}; } else { $Arealday = $Aday } # Cobble together result in same format as input my $Adate = join "/", $Amonth, $Arealday, $Ayear; my $realanswer = join " ", $Adate, $Atime; print "$stamp + 5 minutes is $realanswer\n";