]> git.proxmox.com Git - pve-common.git/commitdiff
add ability to have multiple timespecs for hours and minutes
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 13 Jun 2017 09:25:34 +0000 (11:25 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 13 Jun 2017 09:36:20 +0000 (11:36 +0200)
so things like: 2,4:0 will work

also add regression tests for this

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/CalendarEvent.pm
test/calendar_event_test.pl

index b27e9684e23a067b0602f2473336240425928c44..c30686d99241b68f152412678f3917f48428ca71 100644 (file)
@@ -128,8 +128,12 @@ sub parse_calendar_event {
 
     if ($time_spec =~ m/^($chars+):($chars+)$/) {
        my ($p1, $p2) = ($1, $2);
 
     if ($time_spec =~ m/^($chars+):($chars+)$/) {
        my ($p1, $p2) = ($1, $2);
-       $parse_single_timespec->($p1, 24, \$matchall_hours, $hours_hash);
-       $parse_single_timespec->($p2, 60, \$matchall_minutes, $minutes_hash);
+       foreach my $p (split(',', $p1)) {
+           $parse_single_timespec->($p, 24, \$matchall_hours, $hours_hash);
+       }
+       foreach my $p (split(',', $p2)) {
+           $parse_single_timespec->($p, 60, \$matchall_minutes, $minutes_hash);
+       }
     } elsif ($time_spec =~ m/^($chars)+$/) { # minutes only
        $matchall_hours = 1;
        foreach my $p (split(',', $time_spec)) {
     } elsif ($time_spec =~ m/^($chars)+$/) { # minutes only
        $matchall_hours = 1;
        foreach my $p (split(',', $time_spec)) {
index 54162551912f93bd05fc14989f88bd8d239c290b..0defafa220fdc24bb0b72054a52d908db1e10f8f 100755 (executable)
@@ -157,6 +157,24 @@ my $tests = [
      ' mon 0 0',
      { error => "unable to parse calendar event - unused parts" },
     ],
      ' mon 0 0',
      { error => "unable to parse calendar event - unused parts" },
     ],
+    [
+     '0,1,3..5',
+     { h => '*', m => [0,1,3,4,5], dow => $alldays },
+     [
+       [0, 60],
+       [60, 3*60],
+       [5*60, 60*60]
+     ]
+    ],
+    [
+     '2,4:0,1,3..5',
+     { h => [2,4], m => [0,1,3,4,5], dow => $alldays },
+     [
+       [0, 2*60*60],
+       [2*60*60 + 60, 2*60*60 + 3*60],
+       [2*60*60 + 5*60, 4*60*60]
+     ]
+    ],
 ];
 
 foreach my $test (@$tests) {
 ];
 
 foreach my $test (@$tests) {