morgon has asked for the wisdom of the Perl Monks concerning the following question:
I am looking for a better way to do some rather simple date-arithmetic.
At the moment I am using the DateTime-Module but I just reinstalled it on a new system and I am shocked on how much dependencies it pulls in.
I know there is a plethora of date-modules on CPAN and as I am too lazy to check them all out myself I hope for some pointers for something more lightweight...
So my ideal solution would be using only core-modules while not getting too complicated or at least using modules that don't pull in half of cpan.
What I need is a logic that produces a date depending on the current day:
If the current day is a Thursday I want the date of the following day.
If the current day is a Friday I want the date of this day.
If the current day is anything else I want the date of the preceeding Friday.
Here is what I do at the monent:
Many thanks!use DateTime; my $td = DateTime->today; my $days_since_friday = ($td->day_of_week - 5) % 7; my $days_to_subtract = $days_since_friday == 6 ? -1 : $days_since_frid +ay; $td->subtract( days => $days_to_subtract ); print $td->strftime("%d%m%y");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date arithmetic
by hippo (Archbishop) on Jan 26, 2018 at 10:14 UTC | |
by Perl300 (Friar) on Apr 02, 2018 at 16:28 UTC | |
|
Re: date arithmetic
by QM (Parson) on Jan 26, 2018 at 10:00 UTC | |
|
Re: date arithmetic
by thanos1983 (Parson) on Jan 26, 2018 at 10:17 UTC | |
|
Re: date arithmetic
by poj (Abbot) on Jan 26, 2018 at 15:59 UTC | |
|
Re: date arithmetic
by ikegami (Patriarch) on Jan 26, 2018 at 17:44 UTC | |
|
Re: date arithmetic
by karlgoethebier (Abbot) on Jan 26, 2018 at 16:15 UTC |