#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 4;
use DateTime;
my $dt1 = DateTime->new ( year => 2015, month => 6, day => 1 );
my $dt2 = DateTime->new ( year => 2015, month => 6, day => 30 );
my $duration = $dt1->delta_days ($dt2);
is $duration->days, 29, 'Without delta, more than a week';
is $duration->delta_days, 29, 'With delta, more than a week';
$dt2 = DateTime->new ( year => 2015, month => 6, day => 3 );
$duration = $dt1->delta_days ($dt2);
is $duration->days, 2, 'Without delta, less than a week';
is $duration->delta_days, 2, 'With delta, less than a week';
Test 1 fails for me (with DateTime 1.20) but the others all pass. This fits with the description of the days() method on a duration which says:
These methods return numbers indicating how many of the given unit the object represents, after having done a conversion to any larger units. For example, days are first converted to weeks, and then the remainder is returned.
|