| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use File::Spec; |
| 5 |
use Test::More; |
| 6 |
|
| 7 |
use DateTime::TimeZone; |
| 8 |
|
| 9 |
{ |
| 10 |
my @all = DateTime::TimeZone::all_names(); |
| 11 |
ok( scalar @all > 50, 'there are more than 50 names in the catalog' ); |
| 12 |
ok( |
| 13 |
( grep { $_ eq 'America/Chicago' } @all ), |
| 14 |
'America/Chicago is in the list of all names' |
| 15 |
); |
| 16 |
|
| 17 |
my $all = DateTime::TimeZone::all_names(); |
| 18 |
ok( ref $all, 'all_names() returns ref in scalar context' ); |
| 19 |
} |
| 20 |
|
| 21 |
{ |
| 22 |
my @cats = DateTime::TimeZone::categories(); |
| 23 |
my %cats = map { $_ => 1 } @cats; |
| 24 |
for my $c ( |
| 25 |
qw( Africa |
| 26 |
America |
| 27 |
Antarctica |
| 28 |
Asia |
| 29 |
Atlantic |
| 30 |
Australia |
| 31 |
Europe |
| 32 |
Indian |
| 33 |
Pacific |
| 34 |
) |
| 35 |
) { |
| 36 |
ok( $cats{$c}, "$c is in categories list" ); |
| 37 |
} |
| 38 |
|
| 39 |
my $cats = DateTime::TimeZone::categories(); |
| 40 |
ok( ref $cats, 'categories() returns ref in scalar context' ); |
| 41 |
} |
| 42 |
|
| 43 |
{ |
| 44 |
my %links = DateTime::TimeZone::links(); |
| 45 |
is( $links{Israel}, 'Asia/Jerusalem', 'Israel links to Asia/Jerusalem' ); |
| 46 |
is( $links{UCT}, 'UTC', 'UCT links to UTC' ); |
| 47 |
|
| 48 |
my $links = DateTime::TimeZone::links(); |
| 49 |
ok( ref $links, 'links() returns ref in scalar context' ); |
| 50 |
} |
| 51 |
|
| 52 |
{ |
| 53 |
my @names = DateTime::TimeZone::names_in_category('America'); |
| 54 |
my %names = map { $_ => 1 } @names; |
| 55 |
for my $n (qw( Chicago Adak )) { |
| 56 |
ok( exists $names{$n}, "$n is in America category" ); |
| 57 |
} |
| 58 |
|
| 59 |
my $names = DateTime::TimeZone::names_in_category('America'); |
| 60 |
ok( ref $names, 'names_in_category() returns ref in scalar context' ); |
| 61 |
is_deeply( |
| 62 |
\@names, $names, |
| 63 |
'names_in_category() returns same values in list and scalar context' |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
{ |
| 68 |
my @names = DateTime::TimeZone->names_in_category('America'); |
| 69 |
my %names = map { $_ => 1 } @names; |
| 70 |
for my $n (qw( Chicago Adak )) { |
| 71 |
ok( |
| 72 |
exists $names{$n}, |
| 73 |
"$n is in America category (names_in_category() called as class method)" |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
{ |
| 79 |
my @countries = DateTime::TimeZone::countries(); |
| 80 |
my %countries = map { $_ => 1 } @countries; |
| 81 |
for my $c (qw( jp us )) { |
| 82 |
ok( exists $countries{$c}, "$c is in the list of countries" ); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
{ |
| 87 |
my @zones = DateTime::TimeZone::names_in_country('jp'); |
| 88 |
is( @zones, 1, 'one zone for Japan' ); |
| 89 |
is( $zones[0], 'Asia/Tokyo', 'zone for Japan is Asia/Tokyo' ); |
| 90 |
} |
| 91 |
|
| 92 |
{ |
| 93 |
my @zones = DateTime::TimeZone::names_in_country('JP'); |
| 94 |
is( @zones, 1, 'one zone for Japan' ); |
| 95 |
is( |
| 96 |
$zones[0], 'Asia/Tokyo', |
| 97 |
'zone for Japan is Asia/Tokyo (uc country code)' |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
{ |
| 102 |
my @zones = DateTime::TimeZone->names_in_country('cl'); |
| 103 |
is( @zones, 4, 'four zones for Chile' ); |
| 104 |
is_deeply( |
| 105 |
[ sort @zones ], |
| 106 |
[ |
| 107 |
'America/Coyhaique', 'America/Punta_Arenas', 'America/Santiago', |
| 108 |
'Pacific/Easter' |
| 109 |
], |
| 110 |
'zones for Chile are America/Coyhaique, America/Punta_Arenas, America/Santiago, and Pacific/Easter' |
| 111 |
); |
| 112 |
} |
| 113 |
|
| 114 |
{ |
| 115 |
my @zones = DateTime::TimeZone::names_in_country('us'); |
| 116 |
is( |
| 117 |
$zones[0], 'America/New_York', |
| 118 |
'First timezone by country in US is America/New_York' |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
{ |
| 123 |
my $zones = DateTime::TimeZone::names_in_country('us'); |
| 124 |
is( |
| 125 |
$zones->[0], 'America/New_York', |
| 126 |
'First timezone by country in US is America/New_York - scalar context' |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
done_testing(); |