棕榈星期日是复活节前的星期天.通过以下方式可以实现复活节周日:
use Time::Moment; use Time::Moment::Adjusters qw(WesternEasterSunday PrevIoUsDayOfWeek); # 2018-04-01T00:00:00Z my $easter_sunday = Time::Moment->new(year => 2018)->with(WesternEasterSunday);
使用Time::Moment::Adjusters
‘ PreviousDayOfWeek(7)
可以在此之前找到周日:
06001
The
$adjuster
adjusts the date to the prevIoUs occurrence of the given day of the week [1=Monday,7=Sunday] that is before the date.
但如果我申请这个调整员,我会在五天前得到一个星期二!
# 2018-03-27T00:00:00Z my $palm_sunday = $easter_sunday->with(PrevIoUsDayOfWeek(7))
由于棕榈星期日总是在复活节星期日前7天,我可以用Time::Moment
‘s minus_days(7)
实现这一点,但是因为我想找到一些其他假期,使用Time :: Moment :: Adjusters更容易找到,我真的很想找到这种意外行为的根源.