Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Gettting the last Friday of every month using Time::Piece # evolution of old modules

by LanX (Cardinal)
on Jul 01, 2014 at 14:38 UTC ( #1091849=note: print w/replies, xml ) Need Help??


in reply to Re^4: Gettting the last Friday of every month using Time::Piece
in thread Gettting the last Friday of every month using Time::Piece

> Where is Time::Piece::_wday explained?

This ...

> corelist Time::Piece Time::Piece was first released with perl 5.009005

... and this ...

The module actually implements most of an interface described by Larry Wall on the perl5-porters mailing list here: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-01/msg00241.html

... explain that ...

  • it's popular because it is core and old
  • it's documentation style is not "main stream", because it is old

If you don't like it ...

  • either use a more "modern" module from CPAN
  • or try to improve the documentation to your "standards", like toolic already explained.

That's the normal evolution of open source software! :)

Cheers Rolf

(addicted to the Perl Programming Language)

  • Comment on Re^5: Gettting the last Friday of every month using Time::Piece # evolution of old modules
  • Download Code

Replies are listed 'Best First'.
Re^6: Gettting the last Friday of every month using Time::Piece # evolution of old modules
by Jim (Curate) on Jul 03, 2014 at 00:10 UTC
    If you don't like it … use a more "modern" module from CPAN.

    This is the raison d'Ítre of the DateTime project:  to get right what a plethora of other Perl date and time modules got wrong—or wrongish. The noble and ambitious purpose of the DateTime project and its suite of modules is explained by the project's leader, Dave Rolsky, in his 2003 Perl.com article titled The Many Dates and Times of Perl.

    Here's a short Perl script that demonstrates using the DateTime module to compute the last day of the month for a given day of the week—a generalization of the subject of this thread. Notice the dearth of explanatory comments in the script. They're not really needed due to the clarity of the method and parameter names. My choices of variable names flowed naturally and easily from the method names.

    use strict; use warnings; use DateTime; @ARGV == 3 or die "Usage: perl $0 <day_of_week> <month> <year>\n"; my $day_of_week = shift; # (1 is Monday, 7 is Sunday) my $month = shift; my $year = shift; $day_of_week =~ m/^[1-7]$/ or die "Invalid day of week: $day_of_week\n +"; $month =~ m/^(?:[1-9]|1[012])$/ or die "Invalid month: $month\n"; print last_day_of_week_of_month($day_of_week, $month, $year), "\n"; exit 0; sub last_day_of_week_of_month { my $day_of_week = shift; # (1 is Monday, 7 is Sunday) my $month = shift; my $year = shift; my $last_day_of_month = DateTime->last_day_of_month( year => $year, month => $month +); my $day_of_week_of_last_day_of_month = $last_day_of_month->day_of_week(); my $last_day_of_week_of_month = $last_day_of_month->day() - (($day_of_week_of_last_day_of_month - $day_of_week) % 7); return $last_day_of_week_of_month; }

    Update:  Changed the name of the function from get_last_day_of_week_of_month to last_day_of_week_of_month to conform to the standard DateTime naming convention.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2021-04-13 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?