perl – 寻找棕榈星期天

前端之家收集整理的这篇文章主要介绍了perl – 寻找棕榈星期天前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
棕榈星期日是复活节前的星期天.通过以下方式可以实现复活节周日:

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::AdjustersPreviousDayOfWeek(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更容易找到,我真的很想找到这种意外行为的根源.

解决方法

谢谢Simon的 reportPR,感谢@simbabque的测试!我已发货 v0.44 to CPAN.您是开源社区的优秀公民!

– chansen

猜你在找的Perl相关文章