DateTimeX-Moment
view release on metacpan or search on metacpan
t/11duration.t view on Meta::CPAN
is( $dur->delta_nanoseconds, 9, "delta_nanoseconds" );
is( $dur->in_units('months'), 14, "in_units months" );
is( $dur->in_units('days'), 25, "in_units days" );
is( $dur->in_units('minutes'), 367, "in_units minutes" );
is( $dur->in_units('seconds'), 8, "in_units seconds" );
is(
$dur->in_units( 'nanoseconds', 'seconds' ), 9,
"in_units nanoseconds, seconds"
);
is( $dur->in_units('years'), 1, "in_units years" );
is( $dur->in_units( 'months', 'years' ), 2, "in_units months, years" );
is( $dur->in_units('weeks'), 3, "in_units weeks" );
is( $dur->in_units( 'days', 'weeks' ), 4, "in_units days, weeks" );
is( $dur->in_units('hours'), 6, "in_units hours" );
is( $dur->in_units( 'minutes', 'hours' ), 7, "in_units minutes, hours" );
is(
$dur->in_units('nanoseconds'), 8_000_000_009,
"in_units nanoseconds"
);
my (
$years, $months, $weeks, $days, $hours,
$minutes, $seconds, $nanoseconds
)
= $dur->in_units(
qw( years months weeks days hours
minutes seconds nanoseconds )
);
is( $years, 1, "in_units years, list context" );
is( $months, 2, "in_units months, list context" );
is( $weeks, 3, "in_units weeks, list context" );
is( $days, 4, "in_units days, list context" );
is( $hours, 6, "in_units hours, list context" );
is( $minutes, 7, "in_units minutes, list context" );
is( $seconds, 8, "in_units seconds, list context" );
is( $nanoseconds, 9, "in_units nanoseconds, list context" );
ok( $dur->is_positive, "should be positive" );
ok( !$dur->is_zero, "should not be zero" );
ok( !$dur->is_negative, "should not be negative" );
ok( $dur->is_limit_mode, "limit mode" );
}
{
my %pairs = (
years => 1,
months => 2,
weeks => 3,
days => 4,
hours => 6,
minutes => 7,
seconds => 8,
nanoseconds => 9,
);
my $dur = DateTimeX::Moment::Duration->new( %pairs );
my $calendar_dur = $dur->calendar_duration;
is( $calendar_dur->delta_months, 14, "date - delta_months is 14" );
is( $calendar_dur->delta_minutes, 0, "date - delta_minutes is 0" );
is( $calendar_dur->delta_seconds, 0, "date - delta_seconds is 0" );
is(
$calendar_dur->delta_nanoseconds, 0,
"date - delta_nanoseconds is 0"
);
ok( $calendar_dur->is_limit_mode, "limit mode" );
my $clock_dur = $dur->clock_duration;
is( $clock_dur->delta_months, 0, "time - delta_months is 0" );
is( $clock_dur->delta_minutes, 367, "time - delta_minutes is 367" );
is( $clock_dur->delta_seconds, 8, "time - delta_seconds is 8" );
is( $clock_dur->delta_nanoseconds, 9, "time - delta_nanoseconds is 9" );
ok( $clock_dur->is_limit_mode, "limit mode" );
}
{
my $dur = DateTimeX::Moment::Duration->new( days => 1 );
ok( $dur->is_limit_mode, "limit mode" );
}
my $leap_day = DateTimeX::Moment->new(
year => 2004, month => 2, day => 29,
time_zone => 'UTC',
);
{
my $new = $leap_day + DateTimeX::Moment::Duration->new(
years => 1,
);
is( $new->date, '2005-02-28', "new date should be 2005-02-28" );
}
{
my $inverse = DateTimeX::Moment::Duration->new(
years => 1, months => 1,
weeks => 1, days => 1,
hours => 1, minutes => 2, seconds => 3,
)->inverse;
is( $inverse->years, 1, 'inverse years should be positive' );
is( $inverse->months, 1, 'inverse months should be positive' );
is( $inverse->weeks, 1, 'inverse weeks should be positive' );
is( $inverse->days, 1, 'inverse days should be positive' );
is( $inverse->hours, 1, 'inverse hours should be positive' );
is( $inverse->minutes, 2, 'inverse minutes should be positive' );
is( $inverse->seconds, 3, 'inverse minutes should be positive' );
is(
$inverse->delta_months, -13,
'inverse delta months should be negative'
);
is( $inverse->delta_days, -8, 'inverse delta months should be negative' );
is(
$inverse->delta_minutes, -62,
'inverse delta minutes should be negative'
);
is(
$inverse->delta_seconds, -3,
'inverse delta seconds should be negative'
);
ok( $inverse->is_negative, "should be negative" );
ok( !$inverse->is_zero, "should not be zero" );
ok( !$inverse->is_positive, "should not be positivea" );
( run in 2.714 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )