Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env perl6
use Term::ANSIColor;
constant @months = <January February March April May June July
August September October November December>;
my @days = <Su Mo Tu We Th Fr Sa>;
sub center(Str $text, Int $width) {
my $prefix = ' ' x ($width - $text.chars) div 2;
my $suffix = ' ' x $width - $text.chars - $prefix.chars;
return $prefix ~ $text ~ $suffix;
}
sub MAIN(Bool :$m = False, Int :$year = Date.today.year, Int :$month = Date.today.month) {
my $dt-month-start = Date.new(:year($year), :month($month), :day(1) );
my $dt = $dt-month-start;
my $ss = ($dt.day-of-week - $m) % 7;
my @slots = ' ' xx $ss;
if $m {
@days.push: @days.shift
}
my $days-in-month = $dt.days-in-month;
for $ss ..^ $ss + $days-in-month {
@slots[$_] = $dt.day.fmt("%2d");
$dt++
}
my $weekdays = @days.join: " ";
my $months = center(@months[$month-1] ~ " " ~ $year, $weekdays.chars);
my $output = $months ~ "\n" ~ $weekdays ~ "\n";
my $today = Date.today;
$dt = $dt-month-start;
for @slots.kv -> $k, $v {
$output ~= BOLD if $dt == $today;
$output ~= "$v ";
$output ~= RESET if $dt == $today;
next if $v eq ' ';
$dt++;
$output ~= "\n" if ($k+1) %% 7 or $v == $days-in-month;
}
print $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.