aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-31 20:41:47 +0100
committerGitHub <noreply@github.com>2022-07-31 20:41:47 +0100
commit9f909f6b6c2dc9dbee9647a71719952cf20f60e2 (patch)
tree48a06746a6080f61955e48bec53b4f0c0cad7b26
parenta0c35154601c3a77379ce91bde9f02af6979c225 (diff)
parent675100aaea984b1fb393bc9b3fae3908a56d73d6 (diff)
downloadperlweeklychallenge-club-9f909f6b6c2dc9dbee9647a71719952cf20f60e2.tar.gz
perlweeklychallenge-club-9f909f6b6c2dc9dbee9647a71719952cf20f60e2.tar.bz2
perlweeklychallenge-club-9f909f6b6c2dc9dbee9647a71719952cf20f60e2.zip
Merge pull request #6531 from LubosKolouch/master
feat(challenge-175/lubos-kolouch/perl/ch-1/pl): Challenge 175 Task 1 LK Perl
-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;