[pve-devel] [PATCH common] calendarevent: change sorting of hours and minutes to numeric
Dominik Csapak
d.csapak at proxmox.com
Tue May 30 15:30:22 CEST 2017
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 at proxmox.com>
---
src/PVE/CalendarEvent.pm | 4 ++--
test/calendar_event_test.pl | 27 +++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
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) {
--
2.11.0
More information about the pve-devel
mailing list