Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created October 5, 2022 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/b1a3eb9f870cb7c6af384763f2fa2a80 to your computer and use it in GitHub Desktop.
Save gfldex/b1a3eb9f870cb7c6af384763f2fa2a80 to your computer and use it in GitHub Desktop.
multi sub MAIN(Bool :$S, Bool :$three) {
constant @months = <January February March April May June July August September October November December>;
my @week-days = $S ?? <Su Mo Tu We Th Fr Sa> !! <Mo Tu We Th Fr Sa Su>;
my &start-week-day = $S ?? { .[0].day-of-week % 7 } !! { .[0].day-of-week - 1 }
my $month-offset = $three ?? -1 !! 0;
loop {
$_ = now.Date.truncated-to('month');
$_ = .earlier(:month(1)) if $three;
$_ = .later(:month($++)) if $three;
my $heading = @months[.month - 1] ~ ' ' ~ .year;
put ' ' x 10 - $heading.chars / 2, $heading;
$_ = $_ ..^ .later(:1months);
.put for (|@week-days, |(' ' xx .&start-week-day), |$_».day».fmt('%.2d')).rotor(7, :partial);
put '' if $three;
last if ++$ ≥ 3 || !$three;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment