1use Test::More tests => 43; 2 3BEGIN { use_ok('Time::Piece'); use_ok('Time::Seconds'); } 4 5ok(1); 6 7my $t = gmtime(951827696); # 2000-02-29T12:34:56 8 9is($t->mon, 2); 10is($t->mday, 29); 11 12my $t2 = $t->add_months(1); 13is($t2->year, 2000); 14is($t2->mon, 3); 15is($t2->mday, 29); 16 17my $t3 = $t->add_months(-1); 18is($t3->year, 2000); 19is($t3->mon, 1); 20is($t3->mday, 29); 21 22# this one wraps around to March because of the leap year 23my $t4 = $t->add_years(1); 24is($t4->year, 2001); 25is($t4->mon, 3); 26is($t4->mday, 1); 27 28$t = Time::Piece->strptime("01 01 2010","%d %m %Y"); 29my $t6 = $t->add_months(-12); 30is($t6->year, 2009); 31is($t6->mon, 1); 32is($t6->mday, 1); 33 34my $t7 = $t->add_months(-1); 35is($t7->year, 2009); 36is($t7->mon, 12); 37is($t7->mday, 1); 38 39my $t8 = $t->add_months(-240); 40is($t8->year, 1990); 41is($t8->mon, 1); 42is($t8->mday, 1); 43 44my $t9 = $t->add_months(-13); 45is($t9->year, 2008); 46is($t9->mon, 12); 47is($t9->mday, 1); 48 49eval { $t->add_months(); }; 50like($@, qr/add_months requires a number of months/); 51 52# Tests for Time::Seconds start here 53my $s = $t - $t7; 54is($s->minutes, 44640); 55is($s->hours, 744); 56is($s->days, 31); 57is(int($s->weeks), 4); 58is(int($s->months), 1); 59is(int($s->years), 0); 60 61$s2 = $s->copy; 62is($s2->minutes, 44640, 'Copy Time::Seconds object'); 63$s2 = $s->copy + 60; 64is($s2->minutes, 44641, 'Add integer to Time::Seconds object'); 65$s2 += ONE_HOUR; 66is($s2->minutes, 44701, 'Add exported constant to Time::Seconds object'); 67$s2 += $s2; 68is($s2->minutes, 89402, 'Add one Time::Seconds object to another'); 69 70$s2 += 300 * ONE_DAY; 71is(int($s2->financial_months), 12); 72is(int($s2->months), 11); 73 74$s2 = Time::Seconds->new(); 75is($s2->seconds, 0, 'Empty Time::Seconds constructor is 0s'); 76my $s3 = Time::Seconds->new(10); 77$s2 = $s2 + $s3; 78is($s2->seconds, 10, 'Add 2 Time::Seconds objects'); 79$s2 -= $s3; 80is($s2->seconds, 0, 'Subtract one Time::Seconds object from another'); 81 82eval { $s2 = $s2 + $t; }; 83like($@, qr/Can't use non Seconds object in operator overload/); 84