File: 25add-subtract.t

package info (click to toggle)
libdatetime-perl 2%3A1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,504 kB
  • sloc: perl: 2,964; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use strict;
use warnings;

use Test::More;

use DateTime;

# exercises a bug found in Perl version of _normalize_tai_seconds -
# fixed in 0.15
{
    my $dt = DateTime->new( year => 2000, month => 12 );

    $dt->add( months => 1 )->truncate( to => 'month' )
        ->subtract( seconds => 1 );

    is( $dt->year,   2000, 'year is 2001' );
    is( $dt->month,  12,   'month is 12' );
    is( $dt->hour,   23,   'hour is 23' );
    is( $dt->minute, 59,   'minute is 59' );
    is( $dt->second, 59,   'second is 59' );
}

{
    my $dt = DateTime->new( year => 2000, month => 12 );
    my $dt2 = $dt->clone->add( months => 1 )->subtract( seconds => 1 );

    is( $dt2->year,   2000, 'year is 2001' );
    is( $dt2->month,  12,   'month is 12' );
    is( $dt2->hour,   23,   'hour is 23' );
    is( $dt2->minute, 59,   'minute is 59' );
    is( $dt2->second, 59,   'second is 59' );
}

done_testing();