Debian Codegraph @

t/06no-dst.t

raw
1 use strict;
2 use warnings;
3
4 use lib 't/lib';
5 use T::RequireDateTime;
6
7 use Test::More;
8 use Test::Fatal;
9
10 use File::Spec;
11 use Try::Tiny;
12
13 use DateTime;
14
15 {
16 my $dt = DateTime->now;
17 is(
18 exception { $dt->set_time_zone('Pacific/Tarawa') },
19 undef,
20 'time zone without dst change works'
21 );
22
23 is(
24 exception { $dt->set_time_zone('Asia/Dhaka') },
25 undef,
26 'time zone without dst change works (again)'
27 );
28 }
29
30 # This tests a bug that happened when a time zone has a final rule
31 # that does not repeat (no DST changes), such as America/Caracas.
32 {
33 my $tz = DateTime::TimeZone->new( name => 'America/Caracas' );
34 my @last_spans = @{ $tz->{spans} }[ -2, -1 ];
35
36 # This is basically a meta-test to make sure that America/Caracas
37 # has not introduced DST, in which case the bug would no longer
38 # apply.
39 ok(
40 ( !grep { $_->[5] } @last_spans ),
41 'the last two spans for America/Caracas do not have DST'
42 );
43
44 for my $hm (
45 [ 2, 59 ],
46 [ 3, 00 ],
47 [ 5, 00 ],
48 [ 11, 29 ],
49 [ 11, 30 ],
50 ) {
51 my $dt = try {
52 DateTime->new(
53 year => 2007, month => 12, day => 9,
54 hour => $hm->[0], minute => $hm->[1],
55 time_zone => 'America/Caracas',
56 );
57 };
58
59 my $time = sprintf( '%02d:%02d', @{$hm} );
60 is( $@, q{}, "made object in America/Caracas at $time" );
61 }
62 }
63
64 done_testing();