in reply to Re^2: Yesterday's date
in thread Yesterday's date
Note that this approach will have a problem for those days with less than 24 hours
I would be interested to see a test case showing that, if you could provide one. The tests I tried all worked fine, even on 23-hour days. That's why I posted it as-is rather than trying to work around a problem which didn't appear to be there.
Here's my trivial test script for comparison:
use strict; use warnings; use Time::Piece; use Test::More tests => 366 * 2 + 1; my $dstr = '01/01/2023'; for (1 .. 366) { my $t = Time::Piece->strptime ($dstr, '%d/%m/%Y'); my $nt = $t - 86400; isnt $dstr, $nt->dmy ('/'); my $ddiff = $t->mday - $nt->mday; ok ($ddiff < 0 || $ddiff == 1), '1 day different or month wrap'; $dstr = $nt->dmy ('/'); } is $dstr, '31/12/2021';
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Yesterday's date
by Corion (Patriarch) on May 28, 2023 at 14:42 UTC | |
by hippo (Archbishop) on May 28, 2023 at 15:02 UTC | |
by ikegami (Patriarch) on May 31, 2023 at 14:56 UTC |