From 20e659d9585422505fb9b2ab662f2225fc29f654 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:18:47 +0000 Subject: module modified --- challenge-237/mark-anderson/raku/WDOM.rakumod | 26 ++++++++++---------------- 1 file 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..36140c761c 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 + $day; - # 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) } -- cgit From a3367702109c57d9d848fabb73b1b4655aad068f Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:43:27 +0000 Subject: module modified --- challenge-237/mark-anderson/raku/WDOM.rakumod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-237/mark-anderson/raku/WDOM.rakumod b/challenge-237/mark-anderson/raku/WDOM.rakumod index 36140c761c..01bb36e95e 100644 --- a/challenge-237/mark-anderson/raku/WDOM.rakumod +++ b/challenge-237/mark-anderson/raku/WDOM.rakumod @@ -15,7 +15,7 @@ multi method new(:$weekday-of-month!, :$day-of-week!, :$month!, :$year!) my $day = [1..7].rotate($day-of-week - $dt.day-of-week).head; - $day = ($weekday-of-month - 1) * 7 + $day; + $day += ($weekday-of-month - 1) * 7; # Todo: Handle the exception here? Date.new(:$year, :$month, :$day) -- cgit