aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-31 20:44:09 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-31 20:44:09 +0100
commit5b601e7cd7e3650e59a16a85fef9f80e6cb18e61 (patch)
treebc814246d2572610cac6865832cabf5509b4a357
parent80f2c8c7fa1158cd54afca1155fca0f6726890bb (diff)
parent9f909f6b6c2dc9dbee9647a71719952cf20f60e2 (diff)
downloadperlweeklychallenge-club-5b601e7cd7e3650e59a16a85fef9f80e6cb18e61.tar.gz
perlweeklychallenge-club-5b601e7cd7e3650e59a16a85fef9f80e6cb18e61.tar.bz2
perlweeklychallenge-club-5b601e7cd7e3650e59a16a85fef9f80e6cb18e61.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-rw-r--r--challenge-175/lubos-kolouch/perl/ch-1.pl51
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-175/lubos-kolouch/perl/ch-1.pl b/challenge-175/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..311236484f
--- /dev/null
+++ b/challenge-175/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,51 @@
+package main;
+use strict;
+use warnings;
+use DateTime;
+
+sub get_last_sunday {
+ my ( $year, $month ) = @_;
+
+ my $day =
+ DateTime->last_day_of_month( year => $year, month => $month )->day;
+
+ while (1) {
+ my $dt = DateTime->new(
+ year => $year,
+ month => $month,
+ day => $day
+ );
+
+ if ( $dt->day_of_week == 7 ) {
+ return $dt->ymd;
+ }
+
+ $day--;
+ }
+ return 1;
+}
+
+sub get_sundays {
+ my $year = shift;
+
+ my @sundays;
+
+ for ( 1 .. 12 ) {
+ push @sundays, get_last_sunday( $year, $_ );
+ }
+
+ return \@sundays;
+}
+
+use Test::More;
+
+is_deeply(
+ get_sundays(2022),
+ [
+ '2022-01-30', '2022-02-27', '2022-03-27', '2022-04-24',
+ '2022-05-29', '2022-06-26', '2022-07-31', '2022-08-28',
+ '2022-09-25', '2022-10-30', '2022-11-27', '2022-12-25'
+ ]
+);
+done_testing;
+1;