Hi people,
I am trying to parse 2 parameters to a subroutine in a Perl/cgi app; to convert the normal time to epoch time, add no of seconds supplied and then convert that back to normal date format.
for some reason, by shell the subroutine works but not when put in the Perl/Cgi app where it is required.
Using the module::
Time::Local;
here is the code:
----------------------------------------------------------
sub add_time {
my ($timestamp, $time_to_add) = @_;
my ($date, $time, $mon, $dd, $yy, $hh, $mm, $ss);
my ($epoch, $added_time);
&wbsdTest("In add_time: TimeStamp: $timestamp, Time To Add: $time_to_add");
($date, $time) = (split(' ', $timestamp));
($mon, $dd, $yy) = (split('/', $date));
($hh, $mm) = (split(':', $time));
&wbsdTest("In add_time: before Time Local:");
$epoch = timelocal(00, $mm, $hh, $dd, $mon - 1, $yy - 1900);
&wbsdTest("In add_time: After timelocal: $epoch");
$epoch += ($time_to_add * 60);
($ss, $mm, $hh, $dd, $mon, $yy) = (localtime($epoch))[0 .. 5];
$added_time = sprintf("%02d/%02d/%04d %02d:%02d",
$mon + 1, $dd, $yy + 1900, $hh, $mm);
&wbsdTest("In add_time: Returning $add_time");
return($added_time);
}
----------------------------------------------------------
It is at the following section where the apps stops working
$epoch = timelocal(00, $mm, $hh, $dd, $mon - 1, $yy - 1900);
....
any Comments?
any one knows a much simpler way to get this done?
will appreciate any comments !!
I am trying to parse 2 parameters to a subroutine in a Perl/cgi app; to convert the normal time to epoch time, add no of seconds supplied and then convert that back to normal date format.
for some reason, by shell the subroutine works but not when put in the Perl/Cgi app where it is required.
Using the module::
Time::Local;
here is the code:
----------------------------------------------------------
sub add_time {
my ($timestamp, $time_to_add) = @_;
my ($date, $time, $mon, $dd, $yy, $hh, $mm, $ss);
my ($epoch, $added_time);
&wbsdTest("In add_time: TimeStamp: $timestamp, Time To Add: $time_to_add");
($date, $time) = (split(' ', $timestamp));
($mon, $dd, $yy) = (split('/', $date));
($hh, $mm) = (split(':', $time));
&wbsdTest("In add_time: before Time Local:");
$epoch = timelocal(00, $mm, $hh, $dd, $mon - 1, $yy - 1900);
&wbsdTest("In add_time: After timelocal: $epoch");
$epoch += ($time_to_add * 60);
($ss, $mm, $hh, $dd, $mon, $yy) = (localtime($epoch))[0 .. 5];
$added_time = sprintf("%02d/%02d/%04d %02d:%02d",
$mon + 1, $dd, $yy + 1900, $hh, $mm);
&wbsdTest("In add_time: Returning $add_time");
return($added_time);
}
----------------------------------------------------------
It is at the following section where the apps stops working
$epoch = timelocal(00, $mm, $hh, $dd, $mon - 1, $yy - 1900);
....
any Comments?
any one knows a much simpler way to get this done?
will appreciate any comments !!