[pve-devel] [PATCH common 2/3] add ability to have multiple timespecs for hours and minutes
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 13 11:25:34 CEST 2017
so things like: 2,4:0 will work
also add regression tests for this
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PVE/CalendarEvent.pm | 8 ++++++--
test/calendar_event_test.pl | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/PVE/CalendarEvent.pm b/src/PVE/CalendarEvent.pm
index b27e968..c30686d 100644
--- a/src/PVE/CalendarEvent.pm
+++ b/src/PVE/CalendarEvent.pm
@@ -128,8 +128,12 @@ sub parse_calendar_event {
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)) {
diff --git a/test/calendar_event_test.pl b/test/calendar_event_test.pl
index 5416255..0defafa 100755
--- a/test/calendar_event_test.pl
+++ b/test/calendar_event_test.pl
@@ -157,6 +157,24 @@ my $tests = [
' 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) {
--
2.11.0
More information about the pve-devel
mailing list