aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-10-08 19:25:55 +0100
committerGitHub <noreply@github.com>2023-10-08 19:25:55 +0100
commit5240ea1d0ea69daa172cff6a532c25de04c4bfd1 (patch)
treebfde0ee4046925e4e0c9556c2bc0f64425750ebc
parent50ef96e1ce46454072633abc9f11d6a7ec8ea2db (diff)
parenta3367702109c57d9d848fabb73b1b4655aad068f (diff)
downloadperlweeklychallenge-club-5240ea1d0ea69daa172cff6a532c25de04c4bfd1.tar.gz
perlweeklychallenge-club-5240ea1d0ea69daa172cff6a532c25de04c4bfd1.tar.bz2
perlweeklychallenge-club-5240ea1d0ea69daa172cff6a532c25de04c4bfd1.zip
Merge pull request #8828 from andemark/challenge-237
module modified
-rw-r--r--challenge-237/mark-anderson/raku/WDOM.rakumod26
1 files changed, 10 insertions, 16 deletions
diff --git a/challenge-237/mark-anderson/raku/WDOM.rakumod b/challenge-237/mark-anderson/raku/WDOM.rakumod
index 8e96b4b280..01bb36e95e 100644
--- a/challenge-237/mark-anderson/raku/WDOM.rakumod
+++ b/challenge-237/mark-anderson/raku/WDOM.rakumod
@@ -3,26 +3,20 @@ unit class WDOM is Date is export;
multi method new(:$weekday-of-month!, :$day-of-week!, :$month!, :$year! where $weekday-of-month eq 'L'|'Last')
{
my $dt = Date.new(:$year, :$month).last-date-in-month;
- my $d = $dt.day-of-week - $day-of-week;
- $dt - ($d >= 0 ?? $d !! 7 + $d)
-}
-multi method new(:$weekday-of-month!, :$day-of-week!, :$month!, :$year! where $weekday-of-month ~~ 1..4)
-{
- my $dt = Date.new(:$year, :$month);
- my $wdom = $day-of-week >= $dt.day-of-week ?? $weekday-of-month - 1
- !! $weekday-of-month;
- $dt += 7 * $wdom + $day-of-week - $dt.day-of-week
+ my $day = [$dt.day-6..$dt.day].rotate($day-of-week - $dt.day-of-week).tail;
+
+ Date.new(:$year, :$month, :$day)
}
-multi method new(:$weekday-of-month!, :$day-of-week!, :$month!, :$year! where $weekday-of-month == 5)
+multi method new(:$weekday-of-month!, :$day-of-week!, :$month!, :$year!)
{
- my $dt = Date.new(:$year, :$month).last-date-in-month;
- my $d = $dt.day-of-week - $day-of-week;
- $dt -= $d >= 0 ?? $d !! 7 + $d;
+ my $dt = Date.new(:$year, :$month);
+
+ my $day = [1..7].rotate($day-of-week - $dt.day-of-week).head;
- return $dt if $dt.day == 29|30|31;
+ $day += ($weekday-of-month - 1) * 7;
- # Todo: Handle the exception here. Just return the 4th day-of-week?
- die "There isn't a 5th $day-of-week in $month $year"
+ # Todo: Handle the exception here?
+ Date.new(:$year, :$month, :$day)
}