aboutsummaryrefslogtreecommitdiff
path: root/challenge-037/dave-jacoby/perl5/ch-1.pl
blob: 68190612283388a07bf4d25a99c8eab92284f087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use feature qw{ postderef say signatures state switch };
no warnings
  qw{ experimental::postderef experimental::smartmatch experimental::signatures };

use DateTime;

my $start = DateTime->new(
    year      => 2019,
    month     => 1,
    day       => 1,
    hour      => 12,
    minute    => 0,
    second    => 0,
    time_zone => 'floating',
);

my $day = DateTime::Duration->new( days => 1 );

my $list  = {};
my $names = {};

# in DateTime, Monday is 1 and Sunday is 7, so weekdays are 1-5,
# or < 6. 
while ( $start->year == 2019 ) {
    if ( $start->day_of_week < 6 ) { $list->{ $start->month }++ }
    $names->{ $start->month } //= $start->month_abbr;
    $start->add($day);
}

for my $m ( 1 .. 12 ) {
    my $month = $names->{$m};
    my $c     = $list->{$m};
    say qq{$month: $c days};
}