DateTime-Moonpig
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
like(exception { $x6 = 100 - $birthday; },
qr/subtracting a date from a number is forbidden/, "x6");
# handy technique
$x7 = $birthday + hours(12); # 1969-04-02 14:38:00
is($x7->st, "1969-04-02 14:38:00", "x7");
$x8 = $birthday - hours(12); # 1969-04-01 14:38:00
is($x8->st, "1969-04-01 14:38:00", "x8");
};
subtest "overloading: plus object" => sub {
no strict 'vars';
no warnings 'once';
my $three_days = MyDaysInterval->new(3);
$y0 = $birthday + $three_days; # 1969-04-05 02:38:00
is($y0->st, "1969-04-05 02:38:00", "y0");
# forbidden
my $pat = qr/no 'as_seconds' method/;
like(exception {
my %arg = (year => 2000, month => 1, day => 1);
$y1 = $birthday + DateTime->new(%arg); # croaks
}, $pat, "y1");
like(exception {
$y2 = $birthday + $birthday; # croaks
}, $pat, "y2");
};
subtest "overloading: minus interval object" => sub {
no strict 'vars';
no warnings 'once';
my $three_days = MyDaysInterval->new(3);
$z2 = $birthday - $three_days; # 1969-03-30 02:38:00
is($z2->st, "1969-03-30 02:38:00", "z2");
# forbidden
like(exception {
$z3 = $three_days - $birthday; # croaks
}, qr/subtracting a date from a scalar object/, "z3");
};
subtest "overloading: minus date object" => sub {
no strict 'vars';
no warnings 'once';
$x0 = $birthday + 10; # 1969-04-02 02:38:10
is($x0->st, "1969-04-02 02:38:10", "x0");
$z4 = $x0 - $birthday; # 10
is($z4, 10, "z4");
$z5 = $birthday - $x0; # -10
is($z5, -10, "z5");
package Feb13; # Silly example
sub new {
my ($class) = @_;
bless [ "DUMMY" ] => $class;
}
sub epoch { return 1234567890 } # Feb 13 23:31:30 2009 UTC
package main;
my $feb13 = Feb13->new();
$feb13_dt = DateTime->new( year => 2009,
month => 2,
day => 13,
hour => 23,
minute => 31,
second => 30,
time_zone => "UTC",
);
$z6 = $birthday - $feb13; # -1258232010
is($z6, -1258232010, "z6");
$z7 = $birthday - $feb13_dt; # -1258232010
is($z7, -1258232010, "z7");
$z8 = $feb13 - $birthday; # 1258232010
is($z8, +1258232010, "z8");
# WATCH OUT - will NOT return 1258232010
$z9 = $feb13_dt - $birthday; # returns a DateTime::Duration object
is(ref $z9, "DateTime::Duration", "z9 is a Datetime::Duration");
};
subtest "DST example" => sub {
no strict 'vars';
$a_day = DateTime::Moonpig->new( year => 2007,
month => 3,
day => 11,
hour => 1,
minute => 0,
second => 0,
time_zone => "America/New_York",
);
$next_day = $a_day->plus(24*3600);
is($next_day->hms(":"), "02:00:00", "dst");
};
subtest "number of days in month" => sub {
is (DateTime::Moonpig->new( year => 1969,
month => 4,
day => 2,
)
->number_of_days_in_month(),
30, "April 1969 -> 30");
};
done_testing;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 5.735 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )