line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Calendar; |
2
|
2
|
|
|
2
|
|
485475
|
use Mojo::Base -base; |
|
2
|
|
|
|
|
164250
|
|
|
2
|
|
|
|
|
19
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
580
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
117
|
|
7
|
2
|
|
|
2
|
|
1918
|
use DateTime; |
|
2
|
|
|
|
|
962299
|
|
|
2
|
|
|
|
|
149
|
|
8
|
2
|
|
|
2
|
|
1486
|
use DateTime::Format::Flexible; |
|
2
|
|
|
|
|
266811
|
|
|
2
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has [qw(from)]; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'datetime' => sub { |
13
|
|
|
|
|
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return $self->from if (ref($self->from) eq 'DateTime'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
if ($self->from) { |
18
|
|
|
|
|
|
|
if (my $datetime = DateTime::Format::Flexible->parse_datetime($self->from)) { |
19
|
|
|
|
|
|
|
return $datetime |
20
|
|
|
|
|
|
|
->set_locale($self->locale) |
21
|
|
|
|
|
|
|
->set_time_zone($self->time_zone); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return DateTime->now |
26
|
|
|
|
|
|
|
->set_locale($self->locale) |
27
|
|
|
|
|
|
|
->set_time_zone($self->time_zone); |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has 'locale' => 'en_gb'; |
31
|
|
|
|
|
|
|
has 'time_zone' => 'Europe/London'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
1
|
|
|
1
|
1
|
128
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
5
|
if (@_ > 1) { |
|
|
0
|
|
|
|
|
|
37
|
1
|
|
|
|
|
14
|
return $self->SUPER::new({@_}); |
38
|
|
|
|
|
|
|
} elsif (ref $_[0] eq 'HASH') { |
39
|
0
|
|
|
|
|
0
|
return $self->SUPER::new(@_); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
return $self->SUPER::new(from => $_[0]); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub days_ago { |
46
|
|
|
|
|
|
|
return shift->datetime |
47
|
|
|
|
|
|
|
->clone |
48
|
2
|
|
|
2
|
1
|
2902
|
->subtract(days => shift); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub firt_day_of_next_month { |
52
|
|
|
|
|
|
|
return shift->datetime |
53
|
|
|
|
|
|
|
->clone |
54
|
1
|
|
|
1
|
1
|
2064
|
->add(months => 1) |
55
|
|
|
|
|
|
|
->set_day(1); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub months_ago { |
59
|
|
|
|
|
|
|
return shift->datetime |
60
|
|
|
|
|
|
|
->clone |
61
|
1
|
|
|
1
|
1
|
2221
|
->subtract(months => shift); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub today { |
65
|
1
|
|
|
1
|
1
|
19267
|
return shift; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub tomorrow { |
69
|
|
|
|
|
|
|
return shift->datetime |
70
|
|
|
|
|
|
|
->clone |
71
|
1
|
|
|
1
|
1
|
629
|
->add(days => 1); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub yesterday { |
75
|
1
|
|
|
1
|
1
|
22
|
return shift->days_ago(1); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub AUTOLOAD { |
79
|
1
|
|
|
1
|
|
4
|
my $self = shift; |
80
|
1
|
|
|
|
|
15
|
our $AUTOLOAD; |
81
|
1
|
50
|
|
|
|
12
|
my $method = $AUTOLOAD =~ /::(\w+)$/ ? $1 : undef; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
4
|
$method =~ s/.*:://; |
84
|
1
|
50
|
|
|
|
7
|
return unless $method =~ /[^A-Z]/; # skip DESTROY and all-cap methods |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
33
|
|
|
4
|
return $self->datetime->$method if ($self->datetime && $self->datetime->can($method)); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
croak "Undefined method $AUTOLOAD"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding utf8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Mojo::Calendar - Extended DateTime manipulator |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
use Mojo::Calendar; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Calendar with default date being now |
104
|
|
|
|
|
|
|
my $calendar = Mojo::Calendar->new; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
say $calendar->ymd; |
107
|
|
|
|
|
|
|
say $calendar->his; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
say $calendar->tomorrow->ymd; |
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
|
|
|
|
|
|
|
# Calendar with default date being 2019-03-28 15:29:00 |
118
|
|
|
|
|
|
|
my $calendar = Mojo::Calendar->new('2019-03-28 15:29:00'); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
say $calendar->ymd; |
121
|
|
|
|
|
|
|
say $calendar->his; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<Mojo::Asset::File> is a file storage backend for HTTP content. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 EVENTS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<Mojo::Asset::File> inherits all events from L<Mojo::Asset>. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Mojo::Calendar> inherits all attributes from L<DateTime> and implements |
134
|
|
|
|
|
|
|
the following new ones. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 locale |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $locale = $file->locale; |
139
|
|
|
|
|
|
|
$locale = $file->locale($locale); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Locale, defaults to the C<en_gb>. |
142
|
|
|
|
|
|
|
See L<DateTime::Locale> for more details. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 time_zone |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $time_zone = $file->time_zone; |
147
|
|
|
|
|
|
|
$time_zone = $file->time_zone($time_zone); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Timezone, defaults to the C<Europe/London>. |
150
|
|
|
|
|
|
|
See L<DateTime::TimeZone> for more details. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 METHODS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<Mojo::Calendar> inherits all methods from L<DateTime> and implements |
155
|
|
|
|
|
|
|
the following new ones. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 new |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $datetime = Mojo::Calendar->new; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Calendar object. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 days_ago |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $datetime = $calendar->days_ago(2); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
2 days ago datetime object. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 firt_day_of_next_month |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $datetime = $calendar->firt_day_of_next_month; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
First day of next month datetime object. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 months_ago |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $datetime = $calendar->months_ago(3); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
3 months ago datetime object. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 today |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $datetime = $calendar->today; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
today datetime object. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 tomorrow |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $datetime = $calendar->tomorrow; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
tomorrow datetime object. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 yesterday |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $datetime = $calendar->yesterday; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
yesterday datetime object. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SEE ALSO |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L<DateTime>, L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |