File: 23etc_zones_offset.t

package info (click to toggle)
libdatetime-timezone-perl 1%3A2.47-1%2B2024a
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 104,904 kB
  • sloc: perl: 2,688; sh: 36; makefile: 10
file content (36 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use lib 't/lib';
use T::RequireDateTime;

use Test::More;
use Test::Fatal;

my $dt = DateTime->new( year => 2020 );

for my $h ( 0 .. 14 ) {
    for my $zone (qw( GMT UTC )) {
        for my $sign (qw( + - )) {
            my $name   = "Etc/$zone$sign$h";
            my $expect = $h * 3600;
            $expect *= -1 if $sign eq '+';
            my $tz = DateTime::TimeZone->new( name => $name );
            is(
                $tz->offset_for_datetime($dt),
                "$expect",
                "$name offset is $expect",
            );
        }
    }
}

for my $bad (qw( Etc/UTC+15 Etc/GMT-15 Etc/UTC+999 )) {
    like(
        exception { DateTime::TimeZone->new( name => $bad ) },
        qr/\Q'$bad'\E is an invalid name/,
        "$bad is an invalid time zone",
    );
}

done_testing();