in reply to Re: Calculating holidays
in thread Calculating holidays

I'd probably write the thanksgiving function like this, because the keep-adding-one pattern gives me the jibblies.
my $dt = DateTime->new(year=>$year, month=>11, day=>22); $dt->add(days=>(4 - $dt->dow())%7);

Replies are listed 'Best First'.
Re^3: Calculating holidays
by haukex (Archbishop) on Jul 27, 2017 at 09:30 UTC

    Yes, that's a good point, the loop isn't very elegant. Personally I still like to anchor things at the beginning or end of the month, so I might write:

    my $dt = DateTime->new(year=>$year, month=>11); $dt->add( days=>(4-$dt->dow())%7, weeks=>3 );

    (But that's just getting nitpicky ;-) )