| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OurCal::Month; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp qw(confess); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
70
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use base qw(OurCal::Span); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
78
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use OurCal::Day; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use OurCal::Month; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
474
|
|
|
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
|
|
|
|
|
|
|
sub prev { |
|
29
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub next { |
|
41
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub as_string { |
|
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
53
|
0
|
|
|
|
|
|
return $self->{_dt}->strftime("%b, %Y"); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 is_this_span |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Calls C |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub is_this_span { |
|
64
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub is_this_month { |
|
76
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub days { |
|
88
|
0
|
|
|
0
|
1
|
|
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) { |
|
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
|
|
|
|
|
|
|
sub number_of_weeks { |
|
107
|
0
|
|
|
0
|
1
|
|
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
|
|
0
|
|
|
|
my $start_of_week = shift || 1; |
|
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
|
|
|
|
|
|
|
1; |