File: 30future-tz.t

package info (click to toggle)
libdatetime-perl 2%3A1.65-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,920 kB
  • sloc: perl: 2,986; sh: 23; makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,708 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More;

use DateTime;

undef $ENV{PERL_DATETIME_DEFAULT_TZ};

#
# This test exercises a bug that occurred when date math did not
# always make sure to update the utc_year attribute of the given
# DateTime.  The sympton was that the time zone future span generation
# would fail because utc_year was less than the span's max_year, so
# span generation wouldn't actually do anything, and it would die with
# "Invalid local time".
#
{

    # Each iteration needs to use a different zone, because if it
    # works once, the generated spans are cached.
    for my $add (
        [ years   => 50, 1,               'America/New_York' ],
        [ days    => 50, 365,             'America/Chicago' ],
        [ minutes => 50, 365 * 1440,      'America/Denver', ],
        [ seconds => 50, 365 * 1440 * 60, 'America/Los_Angeles' ],
        [
            nanoseconds => 50, 365 * 1440 * 60 * 1_000_000_000,
            'America/North_Dakota/Center'
        ],

        [ years   => 750, 1,               'Europe/Paris' ],
        [ days    => 750, 365,             'Europe/London' ],
        [ minutes => 750, 365 * 1440,      'Europe/Brussels', ],
        [ seconds => 750, 365 * 1440 * 60, 'Europe/Vienna' ],
        [
            nanoseconds => 750, 365 * 1440 * 60 * 1_000_000_000,
            'Europe/Prague'
        ],
    ) {

        my $dt = DateTime->now->set( hour => 12 )->set_time_zone( $add->[3] );

        my $new
            = eval { $dt->clone->add( $add->[0], $add->[1] * $add->[2] ) };

        is(
            $@,
            q{},
            "Make sure we can add $add->[1] years worth of $add->[0] in $add->[3] time zone"
        );
    }
}

done_testing();