Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Yesterday's date

by kcott (Archbishop)
on May 30, 2023 at 07:48 UTC ( [id://11152498]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Yesterday's date
in thread Yesterday's date

G'day parv,

hippo's code uses 86400. For those regularly working with dates and times, this might immediately leap out as the number of seconds in a day; for others, it might just be a cryptic number (which takes some thought to understand).

Time::Seconds puts that number into a named constant. From its source:

use constant { ... ONE_DAY => 86_400, ... };

I do believe that ONE_DAY is clearer than 86400. Even more so in this particular instance where "$t - ONE_DAY" aligns with the text in the following printf statement, "Date minus one day".

I don't have a problem with "24 * 60 * 60". I would have used that calculation many times myself, over the decades, where ONE_DAY (or equivalent) was not available. It does, however, seem like extra, unecessary work:

... my $one_day = 24 * 60 * 60; ... $t = $t - $one_day; ...

Unless it's needed more than once, I probably wouldn't bother to "assign that to a local variable":

... $t = $t - 24 * 60 * 60; ...

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-20 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found