1#!/usr/bin/perl -w 2 3use strict; 4 5use Test::More tests => 5; 6 7use DateTime; 8 9# 10# This test exercises a bug that occurred when date math did not 11# always make sure to update the utc_year attribute of the given 12# DateTime. The sympton was that the time zone future span generation 13# would fail because utc_year was less than the span's max_year, so 14# span generation wouldn't actually do anything, and it would die with 15# "Invalid local time". 16# 17{ 18 # Each iteration needs to use a different zone, because if it 19 # works once, the generated spans are cached. 20 foreach my $add ( [ years => 50, 'America/New_York' ], 21 [ days => 50 * 365, 'America/Chicago' ], 22 [ minutes => 50 * 365 * 1440, 'America/Denver', ], 23 [ seconds => 50 * 365 * 1440 * 60, 'America/Los_Angeles' ], 24 [ nanoseconds => 50 * 365 * 1440 * 60 * 1_000_000_000, 25 'America/North_Dakota/Center' ], 26 ) 27 { 28 my $dt = DateTime->now( time_zone => $add->[2] ); 29 30 my $new = eval { $dt->clone->add( $add->[0], $add->[1] ) }; 31 32 ok( ! $@, 33 "Make sure we can add 50 years worth of $add->[0] in $add->[2] time zone" ); 34 } 35} 36