diff options
| author | Duane Powell <duane.r.powell@gmail.com> | 2019-12-04 11:04:45 -0600 |
|---|---|---|
| committer | Duane Powell <duane.r.powell@gmail.com> | 2019-12-04 11:04:45 -0600 |
| commit | b254d8d4b135e6eb0c0431e50ba75b1752060c5b (patch) | |
| tree | 84d5d42aa7377a567c45606f40e2118f36b026b3 /challenge-037 | |
| parent | 8002975b359f6ec0c09119ee722811bf7a403f21 (diff) | |
| download | perlweeklychallenge-club-b254d8d4b135e6eb0c0431e50ba75b1752060c5b.tar.gz perlweeklychallenge-club-b254d8d4b135e6eb0c0431e50ba75b1752060c5b.tar.bz2 perlweeklychallenge-club-b254d8d4b135e6eb0c0431e50ba75b1752060c5b.zip | |
Commit solutions for perl weekly challenge 037
Diffstat (limited to 'challenge-037')
| -rwxr-xr-x | challenge-037/duane-powell/perl5/ch-1.pl | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/challenge-037/duane-powell/perl5/ch-1.pl b/challenge-037/duane-powell/perl5/ch-1.pl new file mode 100755 index 0000000000..13abb0436c --- /dev/null +++ b/challenge-037/duane-powell/perl5/ch-1.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl +use warnings; +use strict; +use DateTime; +use DateTime::Duration; +use feature 'say'; + +# Write a script to calculate the total number of weekdays (Mon-Fri) in each month of the year 2019. + +my $year = shift; + +do { + print <<EOU; +Usage: +$0 year + $0 2019 + $0 2020 +EOU + exit; +} unless $year; + +use constant { + SATURDAY => 6, + SUNDAY => 7, +}; + +my $dt = DateTime->new('year' => $year, 'month' => 1, 'day' => 1); +my $day = DateTime::Duration->new('days' => 1); +my $month = $dt->month; +my $weekday_count = 0; +do { + print $dt->month_abbr; + + do { + $weekday_count++ if ($dt->day_of_week != SUNDAY and $dt->day_of_week != SATURDAY); + $dt->add( $day ); + } until ($dt->month != $month); + + say ": $weekday_count"; + + $month = $dt->month; + $weekday_count = 0; + +} until ($dt->year != $year); + + +__END__ + +./ch-1.pl +Usage: +./ch-1.pl year + ./ch-1.pl 2019 + ./ch-1.pl 2020 + +./ch-1.pl 2019 +Jan: 23 +Feb: 20 +Mar: 21 +Apr: 22 +May: 23 +Jun: 20 +Jul: 23 +Aug: 22 +Sep: 21 +Oct: 23 +Nov: 21 +Dec: 22 + +./ch-1.pl 2020 +Jan: 23 +Feb: 20 +Mar: 22 +Apr: 22 +May: 21 +Jun: 22 +Jul: 23 +Aug: 21 +Sep: 22 +Oct: 22 +Nov: 21 +Dec: 23 |
