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