in reply to Gettting the last Friday of every month using Time::Piece

#!perl use strict; use Time::Piece ; my $year = 2014; foreach my $month ( 1..12 ) { my $t = Time::Piece->strptime("$year/$month/01", "%Y/%m/%d"); my $dd = 34 - $t->_wday; # sun=0 $dd -= 7 if $dd > $t->month_last_day; print "$year $month $dd\n"; }
poj

Replies are listed 'Best First'.
Re^2: Gettting the last Friday of every month using Time::Piece
by Anonymous Monk on Jun 30, 2014 at 17:58 UTC
    Whats with the 34?
    my $dd = 34 - $t->_wday; # sun=0
      35= 5*7 days after the 1st (the "36th") you'll have the same weekday again

      36- _wday gives a Sunday

      2 days before Sunday is Friday => 34- _wday

      ... and so on

      Cheers Rolf

      (addicted to the Perl Programming Language)

        Where is Time::Piece::_wday explained? I realize, of course, that it's documented in perldoc Time::Piece (where the definition of "documented" is "merely mentioned, with an ambiguous comment about it"). More generally, where are any of the of Time::Piece methods explained?