Created
March 3, 2015 22:13
-
-
Save jacoby/130a6f95457486e2317b to your computer and use it in GitHub Desktop.
Calendar, Because
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use feature qw'say state unicode_strings' ; | |
use strict ; | |
use utf8 ; | |
use warnings ; | |
use open ':std', ':encoding(UTF-8)' ; | |
use Template ; | |
use DateTime ; | |
my $now = DateTime->now ; | |
my $start = $now->clone() ; | |
$start->set( day => 1 ) ; | |
my $object ; | |
$object->{ month } = $now->month_name ; | |
$object->{ year } = $now->year ; | |
@{ $object->{ days } } = qw{ M T W T F S S } ; | |
my $month = $now->month ; | |
for ( 0 .. 30 ) { | |
if ( $start->month == $month ) { | |
if ( $start->day == 1 ) { | |
for ( 1 .. $start->dow - 1 ) { | |
push @{ $object->{ cal }->[ $start->week_of_month ] }, ' ' ; | |
} | |
} | |
push @{ $object->{ cal }->[ $start->week_of_month ] }, | |
sprintf '%2d', $start->day ; | |
} | |
$start->add( days => 1 ) ; | |
} | |
my $config = { | |
POST_CHOMP => 0, | |
ABSOLUTE => 1, | |
RELATIVE => 1 | |
} ; | |
my $tt = Template->new( $config ) ; | |
my $template = <<TT; | |
[% month %] [% year %] | |
[% FOREACH d IN days %] [% d %] [% END -%] | |
[% FOREACH week IN cal %] | |
[% FOREACH d IN week %] [% d %] [% END -%] | |
[% END %] | |
TT | |
$tt->process( \$template, $object ) | |
|| die "Template process failed: ", $tt->error(), "\n" ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment