]>
git.proxmox.com Git - pve-common.git/blob - test/calendar_event_test.pl
11 use PVE
::CalendarEvent
;
13 # Time tests should run in a controlled setting
17 my $alldays = [0,1,2,3,4,5,6];
53 [3600+16*60, 3600+30*60 ],
54 [3600+30*60, 3600+45*60 ],
55 [3600+45*60, 3600+12*3600],
56 [13*3600 + 1, 13*3600+15*60],
57 [13*3600 + 15*60, 13*3600+30*60],
58 [13*3600 + 30*60, 13*3600+45*60],
59 [13*3600 + 45*60, 25*3600],
84 [0, 4*86400], # Note: Epoch 0 is Thursday, 1. January 1970
104 { error
=> "wrong order in range 'Fri..Mon'" },
119 [22*60*60, 23*60*60],
120 [22*60*60 + 59*60, 23*60*60]
129 [2*60*60, 2*60*60 + 60]
137 [20*60*60, 20*60*60 + 30*60],
138 [22*60*60 + 30*60, 44*60*60]
143 { error
=> "value '61' out of range" },
147 { error
=> "repetition '61' out of range" },
151 { error
=> "range end '80' out of range" },
155 { error
=> "unable to parse calendar event - unused parts" },
159 { error
=> "unable to parse calendar event - event is empty" },
163 { error
=> "unable to parse calendar event - unused parts" },
179 [2*60*60 + 60, 2*60*60 + 3*60],
180 [2*60*60 + 5*60, 4*60*60]
185 foreach my $test (@$tests) {
186 my ($t, $expect, $nextsync) = @$test;
191 eval { $timespec = PVE
::CalendarEvent
::parse_calendar_event
($t); };
194 if ($expect->{error
}) {
196 ok
(defined($err) == defined($expect->{error
}), "parsing '$t' failed expectedly");
197 die "unable to execute nextsync tests" if $nextsync;
202 foreach my $nt (@$nextsync) {
203 my ($last, $expect_next) = @$nt;
204 my $msg = "next event '$t' $last => ${expect_next}";
205 $timespec->{utc
} = 1;
206 my $next = PVE
::CalendarEvent
::compute_next_event
($timespec, $last);
207 is($next, $expect_next, $msg);
212 my ($calspec, $last) = @_;
213 my $spec = PVE
::CalendarEvent
::parse_calendar_event
($calspec);
214 return PVE
::CalendarEvent
::compute_next_event
($spec, $last);
217 # Test loop termination at CEST/CET switch (cannot happen here in UTC)
218 is(tztest
('mon..fri', timelocal
(0, 0, 0, 28, 9, 2018)),
219 timelocal
(0, 0, 0, 29, 9, 2018));
220 is(tztest
('mon..fri UTC', timelocal
(0, 0, 0, 28, 9, 2018)),
221 timelocal
(0, 0, 0, 29, 9, 2018));
223 # Now in the affected time zone
224 $ENV{TZ
} = ':Europe/Vienna';
226 is(tztest
('mon..fri', timelocal
(0, 0, 0, 28, 9, 2018)),
227 timelocal
(0, 0, 0, 29, 9, 2018));
228 # Specifically requesting UTC in the calendar spec means the resulting output
229 # time as seen locally (timelocal() as opposed to timegm()) is shifted by 1
231 is(tztest
('mon..fri UTC', timelocal
(0, 0, 0, 28, 9, 2018)),
232 timelocal
(0, 0, 1, 29, 9, 2018));