/
ch-1.pl
63 lines (37 loc) · 933 Bytes
/
ch-1.pl
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!perl.exe
use strict;
use warnings;
use DateTime;
# AUTHOR: Robert DiCicco
# DATE: 2022-07-25
# Challenge 175 Last Sunday ( Perl )
my @molen = qw( 31 28 31 30 31 30 31 31 30 31 30 31);
sub CreateDateTime { # create a Date object for year and month
my $y = shift;
my $m = shift;
my $dt = DateTime->last_day_of_month(year => $y, month => $m);
return $dt;
}
sub CheckLeapYear { # Adjust February if leap year
my $dt = shift;
if($dt->is_leap_year){
$molen[1] = 29;
}
}
sub GetLastSunday { # back up until we land on Sunday
my $dt = shift;
my $dow = $dt->day_of_week;
if($dow != 7 ){
$dt->subtract(days=>$dow);
}
return $dt;
}
my $count = 1;
my $year = $ARGV[0];
while( $count <= 12){
my $dt = CreateDateTime($year, $count);
CheckLeapYear($dt);
$dt = GetLastSunday($dt);
print($dt->ymd . "\n");
$count++;
}