line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Calendar; |
2
|
2
|
|
|
2
|
|
391241
|
use Mojo::Base 'DateTime'; |
|
2
|
|
|
|
|
130801
|
|
|
2
|
|
|
|
|
19
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.0.5'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
797170
|
use DateTime::Format::Flexible; |
|
2
|
|
|
|
|
218501
|
|
|
2
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
21
|
|
|
21
|
1
|
11641
|
my $class = shift; |
10
|
21
|
|
|
|
|
29
|
my $args = @_; |
11
|
|
|
|
|
|
|
|
12
|
21
|
50
|
|
|
|
46
|
if (@_ > 1) { |
13
|
21
|
|
|
|
|
76
|
$args = { @_ }; |
14
|
|
|
|
|
|
|
} else { |
15
|
0
|
0
|
|
|
|
0
|
if (ref $_[0] eq 'HASH') { |
16
|
0
|
|
|
|
|
0
|
$args = $_[0]; |
17
|
|
|
|
|
|
|
} else { |
18
|
0
|
|
|
|
|
0
|
$args = { from => $_[0] }; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
21
|
|
|
|
|
32
|
my $datetime; |
23
|
|
|
|
|
|
|
|
24
|
21
|
|
100
|
|
|
61
|
$args->{ locale } ||= 'en_gb'; |
25
|
21
|
|
100
|
|
|
49
|
$args->{ time_zone } ||= 'Europe/London'; |
26
|
|
|
|
|
|
|
|
27
|
21
|
100
|
|
|
|
45
|
if (my $from = delete($args->{ from })) { |
28
|
3
|
|
|
|
|
24
|
$datetime = DateTime::Format::Flexible->parse_datetime($from); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
21
|
100
|
|
|
|
2809
|
if (!$datetime) { |
32
|
18
|
|
|
|
|
70
|
$datetime = $class->SUPER::new(%$args); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $self = $class->SUPER::new( |
36
|
|
|
|
|
|
|
year => $datetime->year, |
37
|
|
|
|
|
|
|
month => $datetime->month, |
38
|
|
|
|
|
|
|
day => $datetime->day, |
39
|
|
|
|
|
|
|
hour => $datetime->hour, |
40
|
|
|
|
|
|
|
minute => $datetime->minute, |
41
|
|
|
|
|
|
|
second => $datetime->second, |
42
|
|
|
|
|
|
|
nanosecond => $datetime->nanosecond, |
43
|
|
|
|
|
|
|
locale => $args->{ locale }, |
44
|
|
|
|
|
|
|
time_zone => $args->{ time_zone }, |
45
|
21
|
|
|
|
|
6305
|
); |
46
|
|
|
|
|
|
|
|
47
|
21
|
|
|
|
|
21890
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub days_ago { |
51
|
|
|
|
|
|
|
return shift |
52
|
|
|
|
|
|
|
->clone |
53
|
6
|
|
|
6
|
1
|
2550
|
->subtract(days => shift); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub days_from_now { |
57
|
|
|
|
|
|
|
return shift |
58
|
|
|
|
|
|
|
->clone |
59
|
3
|
|
|
3
|
1
|
12
|
->add(days => shift); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub first_day_of_next_month { |
63
|
|
|
|
|
|
|
return shift |
64
|
|
|
|
|
|
|
->clone |
65
|
3
|
|
|
3
|
1
|
2403
|
->set_day(1) |
66
|
|
|
|
|
|
|
->months_from_now(1); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub first_day_of_prev_month { |
70
|
|
|
|
|
|
|
return shift |
71
|
0
|
|
|
0
|
1
|
0
|
->set_day(1) |
72
|
|
|
|
|
|
|
->months_ago(1); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub months_ago { |
76
|
|
|
|
|
|
|
return shift |
77
|
|
|
|
|
|
|
->clone |
78
|
3
|
|
|
3
|
1
|
2380
|
->subtract(months => shift); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub months_from_now { |
82
|
|
|
|
|
|
|
return shift |
83
|
|
|
|
|
|
|
->clone |
84
|
3
|
|
|
3
|
1
|
44
|
->add(months => shift); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub today { |
88
|
3
|
|
|
3
|
1
|
2889
|
return shift->clone; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub tomorrow { |
92
|
3
|
|
|
3
|
1
|
1445
|
return shift->days_from_now(1); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub yesterday { |
96
|
3
|
|
|
3
|
1
|
38
|
return shift->days_ago(1); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding utf8 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Mojo::Calendar - Extended DateTime manipulator |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Mojo::Calendar; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Calendar with default date being now |
112
|
|
|
|
|
|
|
my $calendar = Mojo::Calendar->new; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
say $calendar->ymd; |
115
|
|
|
|
|
|
|
say $calendar->his; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
say $calendar->tomorrow->ymd; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Calendar with default date being now |
120
|
|
|
|
|
|
|
my $calendar = Mojo::Calendar->new; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
say $calendar->ymd; |
123
|
|
|
|
|
|
|
say $calendar->his; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Calendar with default date being 2019-03-28 15:29:00 |
126
|
|
|
|
|
|
|
my $calendar = Mojo::Calendar->new('2019-03-28 15:29:00'); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
say $calendar->ymd; |
129
|
|
|
|
|
|
|
say $calendar->his; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Mojo::Calendar> is a DateTime manipulator which includes humman readable methods. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L<Mojo::Calendar> inherits all attributes from L<DateTime>. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 METHODS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<Mojo::Calendar> inherits all methods from L<DateTime> and implements |
142
|
|
|
|
|
|
|
the following new ones. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 new |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $datetime = Mojo::Calendar->new; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Calendar object. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 days_ago |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $datetime = $calendar->days_ago(2); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
2 days since initial datetime. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 days_from_now |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $datetime = $calendar->days_from_now(2); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
2 days from initial datetime. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 first_day_of_next_month |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $datetime = $calendar->first_day_of_next_month; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
First day of next month from initial datetime. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 first_day_of_prev_month |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $datetime = $calendar->first_day_of_prev_month; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
First day of previous month from initial datetime. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 months_ago |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my $datetime = $calendar->months_ago(3); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
3 months since initial datetime. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 months_from_now |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $datetime = $calendar->months_from_now(3); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
3 months from initial datetime. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 today |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
my $datetime = $calendar->today; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
today based on initial datetime. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 tomorrow |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my $datetime = $calendar->tomorrow; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
tomorrow based on initial datetime. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 yesterday |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $datetime = $calendar->yesterday; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
yesterday based on initial datetime. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 SEE ALSO |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L<DateTime>, L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |