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

If $Time::Seconds::ONE_DAY remains constant regardless of current time, then do not see how that would add "clarity" or see its purpose. If 24 *60 *60 conjures up magic number, then just assign that to a local variable.

Replies are listed 'Best First'.
Re^4: Yesterday's date
by kcott (Archbishop) on May 30, 2023 at 07:48 UTC

    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