From: Dominik Csapak Date: Tue, 30 May 2017 13:30:22 +0000 (+0200) Subject: calendarevent: change sorting of hours and minutes to numeric X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=a4200306fe8c25230512f1fdcb74ddfd2b675504 calendarevent: change sorting of hours and minutes to numeric otherwise the numbers are sorted like this: [1,10,11 .. 19, 2, 20, ..] which would lead to the wrong next time also add regression tests for this and mixed forms like: 20..22:*/30 Signed-off-by: Dominik Csapak --- diff --git a/src/PVE/CalendarEvent.pm b/src/PVE/CalendarEvent.pm index f6a11c4..2714841 100644 --- a/src/PVE/CalendarEvent.pm +++ b/src/PVE/CalendarEvent.pm @@ -137,13 +137,13 @@ sub parse_calendar_event { if ($matchall_hours) { $h = '*'; } else { - $h = [ sort keys %$hours_hash ]; + $h = [ sort { $a <=> $b } keys %$hours_hash ]; } if ($matchall_minutes) { $m = '*'; } else { - $m = [ sort keys %$minutes_hash ]; + $m = [ sort { $a <=> $b } keys %$minutes_hash ]; } return { h => $h, m => $m, dow => [ sort keys %$dow_hash ]}; diff --git a/test/calendar_event_test.pl b/test/calendar_event_test.pl index f16393d..ec8fcc0 100755 --- a/test/calendar_event_test.pl +++ b/test/calendar_event_test.pl @@ -106,6 +106,33 @@ my $tests = [ 'mon */15', { h => '*', m => [0, 15, 30, 45], dow => [1]}, ], + [ + '22/1:0', + { h => [22, 23], m => [0], dow => $alldays }, + [ + [0, 22*60*60], + [22*60*60, 23*60*60], + [22*60*60 + 59*60, 23*60*60] + ], + ], + [ + '*/2:*', + { h => [0,2,4,6,8,10,12,14,16,18,20,22], m => '*', dow => $alldays }, + [ + [0, 60], + [60*60, 2*60*60], + [2*60*60, 2*60*60 + 60] + ] + ], + [ + '20..22:*/30', + { h => [20,21,22], m => [0,30], dow => $alldays }, + [ + [0, 20*60*60], + [20*60*60, 20*60*60 + 30*60], + [22*60*60 + 30*60, 44*60*60] + ] + ] ]; foreach my $test (@$tests) {