| 1 | package Vigil::Calendar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | require 5.010; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Time::Local qw(timegm); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '2.1.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use constant MONTHS => { 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use constant BASE_DAYS_IN_MONTH => { 1 => 31, 2 => 28, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use constant DAYS_IN_A_WEEK => 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my ($pkg, $y, $m) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #Default to current date if missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | unless (defined $y && defined $m) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $y and defined $m
MC/DC0%0/2
defined $y and defined $m
defined $y
defined $m
Truth table33%1/3
A and B
A= defined $yB= defined $m
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | $y = $year + 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $m = $mon + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #Validate inputs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | return unless $y =~ /^\d+$/ && $m =~ /^\d+$/ && $m >= 1 && $m <= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$y =~ /^\d+$/ and $m =~ /^\d+$/ and $m >= 1 and $m <= 12
$y =~ /^\d+$/ and $m =~ /^\d+$/ and $m >= 1
$y =~ /^\d+$/ and $m =~ /^\d+$/
MC/DC0%0/4
$y =~ /^\d+$/ and $m =~ /^\d+$/ and $m >= 1 and $m <= 12
$y =~ /^\d+$/
$m =~ /^\d+$/
$m >= 1
$m <= 12
Truth table20%1/5
A and B and C and D
A= $y =~ /^\d+$/B= $m =~ /^\d+$/C= $m >= 1D= $m <= 12
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #Calculate previous and next months/years | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my ($pm, $py) = $m == 1 ? (12, $y - 1) : ($m - 1, $y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my ($nm, $ny) = $m == 12 ? (1, $y + 1) : ($m + 1, $y); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | _year => $y, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | _month => $m, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | _previous_month_number => $pm, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | _previous_month_year => $py, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | _next_month_number => $nm, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | _next_month_year => $ny, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, $pkg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | sub month { return $_[0]->{_month}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub year { return $_[0]->{_year}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub previous_month_number{ return $_[0]->{_previous_month_number}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
previous_month_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub previous_month_year{ return $_[0]->{_previous_month_year}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
previous_month_year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub days_in_previous_month { return $_[0]->days_in_month($_[0]->{_previous_month_year}, $_[0]->{_previous_month_number}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
days_in_previous_month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub next_month_number{ return $_[0]->{_next_month_number}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_month_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub next_month_year{ return $_[0]->{_next_month_year}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_month_year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | sub days_in_next_month { return $_[0]->days_in_month($_[0]->{_next_month_year}, $_[0]->{_next_month_number}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
days_in_next_month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | #Returns an evaluation of the _month in the following list form: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | #($name_of_month, $days_in_previous_month, $days_in_this_month, $days_in_next_month, $is_a_leap_year, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # $name_of_day_of_first_day, $name_of_day_of_last_day, $num_of_sundays) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my @ret_array; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $ret_array[0] = $self->month_name($self->{_month}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $ret_array[1] = $self->days_in_previous_month; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $ret_array[2] = $self->days_in_month; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $ret_array[3] = $self->days_in_next_month; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $ret_array[4] = $self->is_a_leap_year; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $ret_array[5] = $self->dayname(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $ret_array[6] = $self->dayname($self->days_in_month); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @count = $self->_get_sundays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $ret_array[7] = $#count + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return(@ret_array); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | sub is_a_leap_year { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_a_leap_year: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #Returns true if the object year is a leap year, false if it isn't. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | my ($self, $test_year) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | $test_year ||= $self->{_year}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$test_year ||= $self->{"_year"}
MC/DC0%0/2
$test_year ||= $self->{"_year"}
$test_year
$self->{"_year"}
Truth table33%1/3
A ||= B
A= $test_yearB= $self->{"_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | return 1 if $test_year % 4 == 0 && ($test_year % 100 != 0 || $test_year % 400 == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$test_year % 4 == 0 and $test_year % 100 != 0 || $test_year % 400 == 0
$test_year % 100 != 0 or $test_year % 400 == 0
MC/DC33%1/3
$test_year % 4 == 0 and $test_year % 100 != 0 || $test_year % 400 == 0
$test_year % 4 == 0
$test_year % 100 != 0
$test_year % 400 == 0
Truth table50%2/4
A and B or C
A= $test_year % 4 == 0B= $test_year % 100 != 0C= $test_year % 400 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub dayname { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dayname: called CC=8 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my ($self, $dom, $month, $year) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | my $mo = $month // $self->{_month}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$month // $self->{"_month"}
MC/DC0%0/2
$month // $self->{"_month"}
$month
$self->{"_month"}
Truth table33%1/3
A // B
A= $monthB= $self->{"_month"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | my $yr = $year // $self->{_year}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$year // $self->{"_year"}
MC/DC0%0/2
$year // $self->{"_year"}
$year
$self->{"_year"}
Truth table33%1/3
A // B
A= $yearB= $self->{"_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | return unless length($yr) == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | return unless $mo >= 1 && $mo <= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$mo >= 1 and $mo <= 12
MC/DC0%0/2
$mo >= 1 and $mo <= 12
$mo >= 1
$mo <= 12
Truth table33%1/3
A and B
A= $mo >= 1B= $mo <= 12
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Zeller's congruence: https://www.geeksforgeeks.org/dsa/zellers-congruence-find-day-date/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Zeller's congruence: 0 = Saturday, 1 = Sunday ... 6 = Friday | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | my $y = $yr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $m = $mo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($m == 1) { $m = 13; $y--; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | elsif ($m == 2) { $m = 14; $y--; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | my $k = $y % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $j = int($y / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | my $f = int($dom + int((13 * ($m + 1)) / 5) + $k + int($k / 4) + int($j / 4) + 5 * $j) % 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Convert Zeller's (0=Sat) to your system (0=Sun, 6=Sat) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my $dow = ($f + 6) % 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #This is not reliant on the one-based list of week days, so we use a zero-based list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my %days = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 => 'Sunday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 => 'Monday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 => 'Tuesday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 => 'Wednesday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 => 'Thursday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 => 'Friday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 => 'Saturday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | return $days{$dow}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | sub weekday { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weekday: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | my ($self, $dom, $month, $year) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | $dom //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dom //= 1
MC/DC0%0/1
$dom //= 1
$dom
Truth table50%1/2
A
A= $dom
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | $month //= $self->{_month}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$month //= $self->{"_month"}
MC/DC0%0/2
$month //= $self->{"_month"}
$month
$self->{"_month"}
Truth table66%2/3
A //= B
A= $monthB= $self->{"_month"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | $year //= $self->{_year}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$year //= $self->{"_year"}
MC/DC0%0/2
$year //= $self->{"_year"}
$year
$self->{"_year"}
Truth table66%2/3
A //= B
A= $yearB= $self->{"_year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | return 0 unless $dom =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | return unless $dom <= $self->days_in_month($year, $month); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | #Tomohiko Sakamotos Algorithm - https://www.geeksforgeeks.org/dsa/tomohiko-sakamotos-algorithm-finding-day-week/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | my @offset = (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | $year -= $month < 3; # Jan & Feb are considered part of previous year | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | #We add 1 because this module calculates Sunday as 1, not 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | return 1 + (($year + int($year / 4) - int($year / 100) + int($year / 400) + $offset[$month - 1] + $dom) % DAYS_IN_A_WEEK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | sub calendar_week { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
calendar_week: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | #This method takes a day of month as an argument and then returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #the calendar week that day is in based on the objects current | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #year and month. Max value for this is 6. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | return int( ($_[1] + $_[0]->weekday(1) - 2) / 7 ) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub month_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month_name: called CC=5 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | #Convert month number to name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my ($self, $num, $short) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | $num //= $self->{_month}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$num //= $self->{"_month"}
MC/DC0%0/2
$num //= $self->{"_month"}
$num
$self->{"_month"}
Truth table33%1/3
A //= B
A= $numB= $self->{"_month"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | return 0 unless $num >= 1 && $num <= 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$num >= 1 and $num <= 12
MC/DC0%0/2
$num >= 1 and $num <= 12
$num >= 1
$num <= 12
Truth table33%1/3
A and B
A= $num >= 1B= $num <= 12
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | return $short ? substr(MONTHS->{$num}, 0, 3) : MONTHS->{$num}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub month_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month_number: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | #Convert month name to number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my $month = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | $month = lc(substr($month, 0, 3)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my %hash = (jan => '1', feb => '2', mar => '3', apr => '4', may => '5', jun => '6', jul => '7', aug => '8', sep => '9', oct => '10', nov => '11', dec => '12'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | if($hash{$month}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | return($hash{$month}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub weeks_in_month { return 1 + int( ($_[0]->days_in_month($_[1], $_[2]) - (9 - $_[0]->weekday(1, $_[2], $_[1])) + 6) / 7 ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weeks_in_month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | ▶ | sub days_in_month { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
days_in_month: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | my $test_year = shift || $self->{_year}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'_year'}
MC/DC0%0/2
shift() || $self->{'_year'}
shift()
$self->{'_year'}
Truth table33%1/3
A || B
A= shift()B= $self->{'_year'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | ▶ | my $test_month = shift || $self->{_month}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'_month'}
MC/DC0%0/2
shift() || $self->{'_month'}
shift()
$self->{'_month'}
Truth table33%1/3
A || B
A= shift()B= $self->{'_month'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | my %days = %{ BASE_DAYS_IN_MONTH() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | ▶ | $days{2} = 29 if $test_month == 2 && $self->is_a_leap_year($test_year); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$test_month == 2 and $self->is_a_leap_year($test_year)
MC/DC100%2/2
$test_month == 2 and $self->is_a_leap_year($test_year)
$test_month == 2
$self->is_a_leap_year($test_year)
Truth table100%3/3
A and B
A= $test_month == 2B= $self->is_a_leap_year($test_year)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | return($days{$test_month}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub week_definition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
week_definition: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # NOTE: This module uses 1-based weekdays (Sunday = 1, Monday = 2, , Saturday = 7) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # instead of the more common 0-based system (Sunday = 0). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # This was originally done to simplify the calculations in week_definition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # which constructs calendar weeks including spillover from previous/next months. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | #No matter what year or month, the maximum number of possible calendar weeks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | #in any give month is six. Therefore, this method will return the dates, in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | #order, of any calendar week within a month where '1' is the first week and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | #'6' is the last possible week. If the week is not a valid week for that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | #month, then a null value is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $week = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return if $week > $self->weeks_in_month; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my @sunday = $self->_get_sundays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | #Initialize and localize the array that will return the results. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my @evaluated_week; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | #The first week is a special week no day of the week except the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | #day of the week is guaranteed to be a valid date. Therefore we have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | #to find the position in the week for the start of the month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $position = $self->weekday(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if($week == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #if the position is equal to '1', then the first of the month is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | #a sunday and we can proceed as normal, otherwise, we have to muck | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #about with the calculations and return the dates of the previous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #month for the calendar month preceeding the objects month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if($position == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | for($a = 0; $a <= 6; $a++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | #Please see this methods outer 'else' conditional for notes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | #on what we are doing in this for-loop. No test for being | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | #over the number of days for the month is required as this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | #is the first calendar week in the month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $this_day = 1 + $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | push(@evaluated_week, $this_day); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | #Since the first weeks sunday is not on the first calenday day of the week | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #we have to determine what that first days date would be for the previous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | #month that shows up in this months first calendar week. The formula for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # this is the date of the day of the month that is $a numbers subtracted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | #from the maximum number of days in the month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $dipm = $self->days_in_previous_month; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | for($a = ($position - 2); $a >= 0; $a--) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | push(@evaluated_week, $dipm - $a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | #Now that we have determined the dates for the portion of the week prior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | #to the first of the month, we will determine the dates for the days of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | #the calendar week that follow the first day of the month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $day = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | for($a = $position; $a <= DAYS_IN_A_WEEK; $a++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | push(@evaluated_week, $day); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $day++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | #We are not in the first week, therefore everything can go along tickety-boo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | #until we reach the final calendar week for the month. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | #Since we are accepting a real number as the argument but the first sunday | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | #dates are stored as an array, we have to decrement the real number to match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | #the position in the array of sundays. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if($position == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | #1st on a Sunday | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $week -= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | #1st NOT on a Sunday | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $week -= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | #Now, step through seven days and build the array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $next_month_day = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | for($a = 0; $a <= 6; $a++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | #Date of the first day of the calendar week plus the day of the position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | #in the week (minus one cause were in an array). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $this_day = $sunday[$week] + $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | #If this day of the calendar week has a date that is greater than the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | #number of days in the month, then we will instead add in the date of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | #that calendar week position for the following month. The program calling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | #this will have to test the output based on previous output if it wants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | #to make any colouring differences based on the date of that day in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | #calendar week. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if($this_day > $self->days_in_month) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $this_day = ++$next_month_day; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | push(@evaluated_week, $this_day); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return(@evaluated_week); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub ordinal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ordinal: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my ($self, $dom) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | return 'th' if $dom =~ /11$|12$|13$/; # special case teens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | return 'st' if $dom % 10 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | ▶ | return 'nd' if $dom % 10 == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return 'rd' if $dom % 10 == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return 'th'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | ▶ | sub sse_from_ymd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_from_ymd: called CC=4 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | my ($self, $y, $m, $d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | return unless $y && $m && $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$y and $m and $d
$y and $m
MC/DC0%0/3
$y and $m and $d
$y
$m
$d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | return timegm(0, 0, 0, $d, $m - 1, $y - 1900); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub _first_sunday { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_first_sunday: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # NOTE: This module uses 1-based weekdays (Sunday = 1, Monday = 2, , Saturday = 7) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # instead of the more common 0-based system (Sunday = 0). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # This was originally done to simplify the calculations in week_definition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # which constructs calendar weeks including spillover from previous/next months. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | #return $self->{firstsunday} if exists $self->{firstsunday}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $pos = $self->weekday(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | $self->{firstsunday} = ($pos == 1 ? 1 : 9 - $pos); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return $self->{firstsunday}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub _get_sundays { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sundays: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $fs = $self->_first_sunday; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $dim = $self->days_in_month; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my @sundays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | push @sundays, $fs + DAYS_IN_A_WEEK * $_ for 0..5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | @sundays = grep { $_ <= $dim } @sundays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | return @sundays; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||