aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-10-08 14:18:47 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-10-08 14:18:47 +0000
commit20e659d9585422505fb9b2ab662f2225fc29f654 (patch)
tree391de29855aa634adb320ed262413946f07c456b
parent3ef6bb41dfa131467507f1de256dfa0ddd839bf1 (diff)
downloadperlweeklychallenge-club-20e659d9585422505fb9b2ab662f2225fc29f654.tar.gz
perlweeklychallenge-club-20e659d9585422505fb9b2ab662f2225fc29f654.tar.bz2
perlweeklychallenge-club-20e659d9585422505fb9b2ab662f2225fc29f654.zip
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..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)
}