Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Gettting the last Friday of every month using Time::Piece

by poj (Abbot)
on Jun 30, 2014 at 16:49 UTC ( #1091750=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1091750]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2021-04-12 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?