| 1 | package OurCal::Month; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use Carp qw(confess); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use base qw(OurCal::Span); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use OurCal::Day; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use OurCal::Month; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | OurCal::Month - a representation of an OurCal::Month | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||
| 14 | |||||||||||||
| 15 | my $month = OurCal::Month->new( date => '2007-11'); | ||||||||||||
| 16 | |||||||||||||
| 17 | |||||||||||||
| 18 | =head1 METHODS | ||||||||||||
| 19 | |||||||||||||
| 20 | =cut | ||||||||||||
| 21 | |||||||||||||
| 22 | =head2 prev | ||||||||||||
| 23 | |||||||||||||
| 24 | Returns the previous month as an object | ||||||||||||
| 25 | |||||||||||||
| 26 | =cut | ||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub prev { | ||||||||||
|
Subroutine
prev: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||
| 30 | 0 | return $self->_shift($self->{_dt}->clone->subtract( months => 1 )->strftime("%Y-%m")); | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | =head2 next | ||||||||||||
| 35 | |||||||||||||
| 36 | Returns the next month as an object. | ||||||||||||
| 37 | |||||||||||||
| 38 | =cut | ||||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | sub next { | ||||||||||
|
Subroutine
next: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||
| 42 | 0 | return $self->_shift($self->{_dt}->clone->add( months => 1 )->strftime("%Y-%m")); | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | =head2 as_string | ||||||||||||
| 46 | |||||||||||||
| 47 | Returns this month as a string | ||||||||||||
| 48 | |||||||||||||
| 49 | =cut | ||||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub as_string { | ||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||
| 53 | 0 | return $self->{_dt}->strftime("%b, %Y"); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | =head2 is_this_span | ||||||||||||
| 58 | |||||||||||||
| 59 | Calls C<is_this_month> | ||||||||||||
| 60 | |||||||||||||
| 61 | =cut | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub is_this_span { | ||||||||||
|
Subroutine
is_this_span: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||
| 65 | 0 | return $self->is_this_month; | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | =head2 is_this_month | ||||||||||||
| 69 | |||||||||||||
| 70 | Returns whether this month object is also the current month in the real | ||||||||||||
| 71 | world | ||||||||||||
| 72 | |||||||||||||
| 73 | =cut | ||||||||||||
| 74 | |||||||||||||
| 75 | 0 | ▶ | sub is_this_month { | ||||||||||
|
Subroutine
is_this_month: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||
| 77 | 0 | my $now = DateTime->now->truncate( to => 'month' ); | |||||||||||
| 78 | 0 | return $now == $self->{_dt}; | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | =head2 days | ||||||||||||
| 82 | |||||||||||||
| 83 | Returns an array of all the days in this month as objects. | ||||||||||||
| 84 | |||||||||||||
| 85 | =cut | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | ▶ | sub days { | ||||||||||
|
Subroutine
days: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||
| 89 | 0 | my $dt = $self->{_dt}->clone; | |||||||||||
| 90 | |||||||||||||
| 91 | 0 | my @days; | |||||||||||
| 92 | 0 | my $month = $dt->month; | |||||||||||
| 93 | 0 | ▶ | while ($dt->month == $month) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 0 | push @days, $self->_span("OurCal::Day", $dt->strftime("%Y-%m-%d")); | |||||||||||
| 95 | 0 | $dt->add( days => 1); | |||||||||||
| 96 | } | ||||||||||||
| 97 | 0 | return @days; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | =head2 number_of_weeks | ||||||||||||
| 101 | |||||||||||||
| 102 | Returns the number of weeks in this month. | ||||||||||||
| 103 | |||||||||||||
| 104 | =cut | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | sub number_of_weeks { | ||||||||||
|
Subroutine
number_of_weeks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 107 | 0 | my $self = shift; | |||||||||||
| 108 | |||||||||||||
| 109 | # get the last day of the month | ||||||||||||
| 110 | 0 | my $dt = $self->{_dt}->clone; | |||||||||||
| 111 | 0 | my $last = DateTime->last_day_of_month( year => $dt->year, month => $dt->month ); | |||||||||||
| 112 | |||||||||||||
| 113 | 0 | ▶ | my $start_of_week = shift || 1; | ||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 114 | |||||||||||||
| 115 | # Work out what day the first of the month falls on | ||||||||||||
| 116 | 0 | my $first = $dt->clone(); | |||||||||||
| 117 | 0 | $first->set(day => 1); | |||||||||||
| 118 | 0 | my $wday = $first->day_of_week(); | |||||||||||
| 119 | |||||||||||||
| 120 | # And adjust the day to the start of the week | ||||||||||||
| 121 | 0 | $wday = ($wday - $start_of_week + 7) % 7; | |||||||||||
| 122 | |||||||||||||
| 123 | # Then do the calculation to work out the week | ||||||||||||
| 124 | 0 | my $mday = $last->day_of_month_0(); | |||||||||||
| 125 | |||||||||||||
| 126 | 0 | return int ( ($mday + $wday) / 7 ) + 1; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | 2 | 1; | |||||||||||