aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2021-11-13 13:46:32 +0100
committerLubos Kolouch <lubos@kolouch.net>2021-11-13 13:46:32 +0100
commit296aebee4b1c7d91da164033ebecfa47cefbb75c (patch)
tree328017b59f5cf3abf95b56ba380949864f45478b
parent7d8a06e346c3817502495bf9cb5a86634892dfe1 (diff)
downloadperlweeklychallenge-club-296aebee4b1c7d91da164033ebecfa47cefbb75c.tar.gz
perlweeklychallenge-club-296aebee4b1c7d91da164033ebecfa47cefbb75c.tar.bz2
perlweeklychallenge-club-296aebee4b1c7d91da164033ebecfa47cefbb75c.zip
Challenge 137 Task1 Perl LK
-rw-r--r--challenge-138/lubos-kolouch/perl/ch-1.pl41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-138/lubos-kolouch/perl/ch-1.pl b/challenge-138/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..ca8301e52f
--- /dev/null
+++ b/challenge-138/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+use DateTime;
+use List::Util qw/min max/;
+
+sub get_work_days {
+ my $what = shift;
+
+ my $dt_1_1 = DateTime->new(
+ year => $what,
+ month => 1,
+ day => 1);
+
+
+ my $dt_31_12 = DateTime->new(
+ year => $what,
+ month => 12,
+ day => 31);
+
+
+ my $weeks_in_year = $dt_31_12->week_number;
+ $weeks_in_year += 1 if $dt_1_1->week_number != 1;
+
+ my $result = $weeks_in_year * 5;
+
+ # deduct left over days at the end of the year
+ $result -= max(5-$dt_31_12->day_of_week, 0);
+
+ # deduct days at the beginning of the year
+ $result -= min($dt_1_1->day_of_week-1, 5);
+
+ return $result;
+}
+
+use Test::More;
+
+is(get_work_days(2021), 261);
+is(get_work_days(2020), 262);
+
+
+done_testing;