mirror of
git://git.proxmox.com/git/pve-common.git
synced 2025-01-03 09:17:36 +03:00
tests: update to utc flag and add daylight savings test
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
0b7ba0445c
commit
f236e57602
@ -3,12 +3,17 @@
|
|||||||
use lib '../src';
|
use lib '../src';
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use POSIX ();
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Time::Local;
|
use Time::Local;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
use PVE::CalendarEvent;
|
use PVE::CalendarEvent;
|
||||||
|
|
||||||
|
# Time tests should run in a controlled setting
|
||||||
|
$ENV{TZ} = 'UTC';
|
||||||
|
POSIX::tzset();
|
||||||
|
|
||||||
my $alldays = [0,1,2,3,4,5,6];
|
my $alldays = [0,1,2,3,4,5,6];
|
||||||
my $tests = [
|
my $tests = [
|
||||||
[
|
[
|
||||||
@ -183,6 +188,7 @@ foreach my $test (@$tests) {
|
|||||||
my $timespec;
|
my $timespec;
|
||||||
eval { $timespec = PVE::CalendarEvent::parse_calendar_event($t); };
|
eval { $timespec = PVE::CalendarEvent::parse_calendar_event($t); };
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
|
delete $timespec->{utc};
|
||||||
|
|
||||||
if ($expect->{error}) {
|
if ($expect->{error}) {
|
||||||
chomp $err if $err;
|
chomp $err if $err;
|
||||||
@ -197,11 +203,36 @@ foreach my $test (@$tests) {
|
|||||||
|
|
||||||
foreach my $nt (@$nextsync) {
|
foreach my $nt (@$nextsync) {
|
||||||
my ($last, $expect_next) = @$nt;
|
my ($last, $expect_next) = @$nt;
|
||||||
|
|
||||||
my $msg = "next event '$t' $last => ${expect_next}";
|
my $msg = "next event '$t' $last => ${expect_next}";
|
||||||
my $next = PVE::CalendarEvent::compute_next_event($timespec, $last, 1);
|
$timespec->{utc} = 1;
|
||||||
|
my $next = PVE::CalendarEvent::compute_next_event($timespec, $last);
|
||||||
is($next, $expect_next, $msg);
|
is($next, $expect_next, $msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sub tztest {
|
||||||
|
my ($calspec, $last) = @_;
|
||||||
|
my $spec = PVE::CalendarEvent::parse_calendar_event($calspec);
|
||||||
|
return PVE::CalendarEvent::compute_next_event($spec, $last);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test loop termination at CEST/CET switch (cannot happen here in UTC)
|
||||||
|
is(tztest('mon..fri', timelocal(0, 0, 0, 28, 9, 2018)),
|
||||||
|
timelocal(0, 0, 0, 29, 9, 2018));
|
||||||
|
is(tztest('mon..fri UTC', timelocal(0, 0, 0, 28, 9, 2018)),
|
||||||
|
timelocal(0, 0, 0, 29, 9, 2018));
|
||||||
|
|
||||||
|
# Now in the affected time zone
|
||||||
|
$ENV{TZ} = ':Europe/Vienna';
|
||||||
|
POSIX::tzset();
|
||||||
|
is(tztest('mon..fri', timelocal(0, 0, 0, 28, 9, 2018)),
|
||||||
|
timelocal(0, 0, 0, 29, 9, 2018));
|
||||||
|
# Specifically requesting UTC in the calendar spec means the resulting output
|
||||||
|
# time as seen locally (timelocal() as opposed to timegm()) is shifted by 1
|
||||||
|
# hour.
|
||||||
|
is(tztest('mon..fri UTC', timelocal(0, 0, 0, 28, 9, 2018)),
|
||||||
|
timelocal(0, 0, 1, 29, 9, 2018));
|
||||||
|
$ENV{TZ} = 'UTC';
|
||||||
|
POSIX::tzset();
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
Loading…
Reference in New Issue
Block a user