diff options
| author | Matthew Neleigh <matthew.neleigh@gmail.com> | 2025-11-17 15:55:54 -0500 |
|---|---|---|
| committer | Matthew Neleigh <matthew.neleigh@gmail.com> | 2025-11-17 15:55:54 -0500 |
| commit | 4fbb9e3cddc115b656a62b60ad992c44998d0bf7 (patch) | |
| tree | 564776ddfe71c01f01d8cc36b36621251fdf0c81 | |
| parent | d1da7f260175c7d9f93d757df1bccdfe1e3d6d04 (diff) | |
| download | perlweeklychallenge-club-4fbb9e3cddc115b656a62b60ad992c44998d0bf7.tar.gz perlweeklychallenge-club-4fbb9e3cddc115b656a62b60ad992c44998d0bf7.tar.bz2 perlweeklychallenge-club-4fbb9e3cddc115b656a62b60ad992c44998d0bf7.zip | |
modified: challenge-348/mattneleigh/perl/ch-2.pl
| -rwxr-xr-x | challenge-348/mattneleigh/perl/ch-2.pl | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/challenge-348/mattneleigh/perl/ch-2.pl b/challenge-348/mattneleigh/perl/ch-2.pl index 46516f7188..56a3e4098d 100755 --- a/challenge-348/mattneleigh/perl/ch-2.pl +++ b/challenge-348/mattneleigh/perl/ch-2.pl @@ -56,15 +56,19 @@ sub ops_to_make_time_difference{ $start = [ split(/:/, $start) ]; $end = [ split(/:/, $end) ]; - # If the hour of the end time appears to be less - # than that of the start time, assume that it's - # from the next day - $end->[0] += 24 - if($end->[0] < $start->[0]); - - # Convert hours and minutes to just minutes, and - # calculate the difference - $diff = ($end->[0] * 60 + $end->[1]) - ($start->[0] * 60 + $start->[1]); + # Convert the times into numbers of minutes since + # 00:00 + $end = ($end->[0] * 60 + $end->[1]); + $start = ($start->[0] * 60 + $start->[1]); + + # If the end appears to be before the start, + # assume that it's meant to be the next day + $end += 1440 + if($end < $start); + + # Calculate the difference between the start and + # end times + $diff = $end - $start; # Loop over each unit of minutes, determining how # many of each are required to equal the difference |
