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
|
|---|