]> git.proxmox.com Git - pve-common.git/commitdiff
calendarevent: change sorting of hours and minutes to numeric
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 30 May 2017 13:30:22 +0000 (15:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 31 May 2017 06:37:19 +0000 (08:37 +0200)
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 <d.csapak@proxmox.com>
src/PVE/CalendarEvent.pm
test/calendar_event_test.pl

index f6a11c4423e6395c09a39f90735a7b2e97350ba7..2714841c1aab6039c4f6337e348d61d68231734d 100644 (file)
@@ -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 ]};
index f16393d4b78fe66c34cc243505cb0f259bcb2f54..ec8fcc0c84db97a50a583fa3b1dcfd29a4854c3b 100755 (executable)
@@ -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) {