File: 02last-day.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 (50 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use strict;
use warnings;

use Test::Fatal;
use Test::More;

use DateTime;

my @last_day = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
my @leap_last_day = @last_day;
$leap_last_day[1]++;

foreach my $month ( 1 .. 12 ) {
    my $dt = DateTime->last_day_of_month(
        year      => 2001,
        month     => $month,
        time_zone => 'UTC',
    );

    is( $dt->year,  2001,                    'check year' );
    is( $dt->month, $month,                  'check month' );
    is( $dt->day,   $last_day[ $month - 1 ], 'check day' );
}

foreach my $month ( 1 .. 12 ) {
    my $dt = DateTime->last_day_of_month(
        year      => 2004,
        month     => $month,
        time_zone => 'UTC',
    );

    is( $dt->year,  2004,                         'check year' );
    is( $dt->month, $month,                       'check month' );
    is( $dt->day,   $leap_last_day[ $month - 1 ], 'check day' );
}

{
    is(
        exception {
            DateTime->last_day_of_month(
                year       => 2000, month => 1,
                nanosecond => 2000
            );
        },
        undef,
        'last_day_of_month should accept nanosecond'
    );
}

done_testing();