From: Stefan Schantl Date: Thu, 20 May 2021 19:13:50 +0000 (+0200) Subject: time.cgi: Get and manipuate date and time in pure perl X-Git-Tag: v2.25-core158~33^2~10^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=276f938b09075debb6f2aab517f03010c1a4a4a8;p=ipfire-2.x.git time.cgi: Get and manipuate date and time in pure perl Signed-off-by: Stefan Schantl --- diff --git a/html/cgi-bin/time.cgi b/html/cgi-bin/time.cgi index 09ef2aa84b..6bf3dcc843 100644 --- a/html/cgi-bin/time.cgi +++ b/html/cgi-bin/time.cgi @@ -20,6 +20,7 @@ ############################################################################### use strict; +use POSIX qw(strftime); # enable only the following on debugging purpose #use warnings; @@ -180,11 +181,18 @@ if ($timesettings{'VALID'} eq '') } unless ($errormessage) { - $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`; - $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`; - $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`; - $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`; - $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`; + # Get date and time. + my $date = strftime("%m %e %Y %H %M", localtime); + + # Split date string into single values. + my ($month, $day, $year, $hour, $minute) = split(/ /, $date); + + # Assign values to the hash. + $timesettings{'SETMONTH'} = $month; + $timesettings{'SETDAY'} = $day; + $timesettings{'SETYEAR'} = $year; + $timesettings{'SETHOUR'} = $hour; + $timesettings{'SETMINUTES'} = $minute; $_=$timesettings{'SETDAY'}; $timesettings{'SETDAY'}=~ tr/ /0/; }