Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Jim (Curate)
on Jun 30, 2014 at 18:47 UTC ( #1091763=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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? 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?

Replies are listed 'Best First'.
Re^5: Gettting the last Friday of every month using Time::Piece
by runrig (Abbot) on Jun 30, 2014 at 18:56 UTC
    $t->wday # 1 = Sunday $t->_wday # 0 = Sunday $t->day_of_week # 0 = Sunday
    What is unclear? Extrapolating that Sunday+1 == Monday, Sunday+2 = Tuesday, etc.? That one starts at one, and the other two start at zero? That Sunday is considered the start of the week?

      I infer from your response that, as far as you know, the answer to the question I asked is that there is not an explanation of Time::Piece::_wday in the module's documentation. In fact, none of the module's methods are explained in the documentation.

      What is unclear?

      The difference between Time::Piece::_wday and Time::Piece::day_of_week, for example.

      Here's what Dave Rolsky wrote about Time::Piece in his landmark 2003 Perl.com article titled The Many Dates and Times of Perl:

      Written and maintained by Matt Sergeant, this module is based on an interface designed by Larry Wall. It provides a convenient object API for datetimes, though the API is a bit confusing. For example, $time->mon returns the month number (1-12) while $time->month returns the abbreviated name of the month.

      IMHO, because the API is confusing, the methods should properly be explicitly explained in the module's documentation—even those methods that, to an experienced computer programmer, seem plainly obvious from their names alone.

        IMHO, because the API is confusing, the methods should properly be explicitly explained in the module's documentation—even those methods that, to an experienced computer programmer, seem plainly obvious from their names alone.
        Make a request via perlbug. Increase the likelihood of your request being applied by submitting a patch.
        For example, $time->mon returns the month number (1-12) while $time->m +onth returns the abbreviated name of the month.
        Less is more:
        $t->mon # 1 = January $t->_mon # 0 = January $t->monname # Feb $t->month # same as $t->monname $t->fullmonth # February
        I much prefer the above documentation over renaming mon() and month() to month_number_starting_with_January_at_index_zero() and abbreviated_month_name(), or verbose 'explanations' cluttering up the place. Perhaps day_of_week() could say "same as $t->_wday()", but it seems pretty obvious to me that that is the case.
        I infer from your response that, as far as you know, the answer to the question I asked is that there is not an explanation of Time::Piece::_wday in the module's documentation.
        You infer incorrectly. IMHO, the amount of explanation already given is sufficient, and very little, if anything, should be added.
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
    > 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)

      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://1091763]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2020-09-27 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I don’t succeed, I …










    Results (142 votes). Check out past polls.

    Notices?