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