| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | |
|---|
| 5 | use Test::More tests => 73; |
|---|
| 6 | |
|---|
| 7 | use DateTime::Lite; |
|---|
| 8 | |
|---|
| 9 | my @last = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); |
|---|
| 10 | my @leap_last = @last; |
|---|
| 11 | $leap_last[1]++; |
|---|
| 12 | |
|---|
| 13 | foreach my $month (1..12) |
|---|
| 14 | { |
|---|
| 15 | my $dt = DateTime::Lite->last_day_of_month( year => 2001, |
|---|
| 16 | month => $month, |
|---|
| 17 | time_zone => 'UTC', |
|---|
| 18 | ); |
|---|
| 19 | |
|---|
| 20 | is( $dt->year, 2001, 'check year' ); |
|---|
| 21 | is( $dt->month, $month, 'check month' ); |
|---|
| 22 | is( $dt->day, $last[ $month - 1 ], 'check day' ); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | foreach my $month (1..12) |
|---|
| 26 | { |
|---|
| 27 | my $dt = DateTime::Lite->last_day_of_month( year => 2004, |
|---|
| 28 | month => $month, |
|---|
| 29 | time_zone => 'UTC', |
|---|
| 30 | ); |
|---|
| 31 | |
|---|
| 32 | is( $dt->year, 2004, 'check year' ); |
|---|
| 33 | is( $dt->month, $month, 'check month' ); |
|---|
| 34 | is( $dt->day, $leap_last[ $month - 1 ], 'check day' ); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | { |
|---|
| 38 | eval { DateTime::Lite->last_day_of_month( year => 2000, month => 1, nanosecond => 2000 ) }; |
|---|
| 39 | is( $@, '', |
|---|
| 40 | "last_day_of_month should accept nanosecond" ); |
|---|
| 41 | } |
|---|