#!perl -T
can_ok(
'Date::Lectionary::Time'
,
qw(prevSunday)
);
my
$prevSundayTimePieceObject
= prevSunday(Time::Piece->strptime(
"2016-01-01"
,
"%Y-%m-%d"
));
isa_ok(
$prevSundayTimePieceObject
,
'Time::Piece'
);
is(
prevSunday(Time::Piece->strptime(
"2016-01-01"
,
"%Y-%m-%d"
)),
Time::Piece->strptime(
"2015-12-27"
,
"%Y-%m-%d"
),
'Sunday previous to 2016-01-01 is 2015-12-27'
);
is(
prevSunday(Time::Piece->strptime(
"2015-12-27"
,
"%Y-%m-%d"
)),
Time::Piece->strptime(
"2015-12-20"
,
"%Y-%m-%d"
),
'Sunday previous to 2015-12-27 is 2015-12-20'
);
is(
prevSunday(Time::Piece->strptime(
"3098-12-01"
,
"%Y-%m-%d"
)),
Time::Piece->strptime(
"3098-11-27"
,
"%Y-%m-%d"
),
'Sunday previous 3098-12-01 is 3098-11-27'
);
is(
prevSunday(Time::Piece->strptime(
"2016-02-29"
,
"%Y-%m-%d"
)),
Time::Piece->strptime(
"2016-02-28"
,
"%Y-%m-%d"
),
'Sunday previous to 2016-02-29 is 2016-02-28'
);
throws_ok (
sub
{prevSunday(
'2016-01-01'
)},
qr/Method \[prevSunday\] expects an input argument of type Time::Piece\./
,
'String input argument given instead of Time::Piece'
);
throws_ok (
sub
{prevSunday(
undef
)},
qr/Method \[prevSunday\] expects an input argument of type Time::Piece\. The given type could not be determined\./
,
'Undefined input argument given instead of Time::Piece'
);