Minor change to the first response using sprintf instead of ceil and POSIX. Also does not use any additional CPAN modules. This rounds up or down so 6:07 = 6:00, 6:08 = 6:15, 6:22 = 6:15 and 6:23 = 6:30. Note that an hour is added if the rounded minutes are 60. However, to do this correctly, you will need to use the timelocal and localtime functions to add the hour. that is, adding an hour can add a day, a month or a year.
#!/usr/bin/perl my ($hr,$min) = split/:/,$time; my $interimval = ($min/15); my $rounded_min = sprintf "%.0f", $interimval; $rounded_min = $rounded_min * 15; if($rounded_min == 60) { $rounded_min = 0; $hr++; $hr = 0 if($hr == 24); }
cccict
source share