Venus/Date.pm

filter: Statementstmt 92.2% 202 / 219 Branchbran 83.8% 52 / 62 Conditioncond 67.6% 44 / 65 MC/DCmcdc 30.7% 12 / 39 Subroutinesub 87.3% 55 / 63 Podpod 85.1% 40 / 47 totaltotal 81.8% 405 / 495 CC 61 SCAR 11.9
CC
61
Cov
86%
build_arg
10.9
build_args
7.5
set_hms
4.1
CRAP 3.3
« Venus/Replace.pm ↑ Summary Venus/Role/Proxyable.pm »
1 package Venus::Date;
2  
3 2 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Venus::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 base 'Venus::Kind::Utility';
11  
12 2 with 'Venus::Role::Buildable';
13 2 with 'Venus::Role::Explainable';
14  
15 use overload (
16 '""' => 'explain',
17 1 ▶ '!=' => sub{("$_[0]" + 0) != ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
18 2 ▶ '+' => sub{("$_[0]" + 0) + ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 ▶ '-' => sub{("$_[0]" + 0) - ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
20 130 ▶ '0+' => sub{($_[0]->epoch + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 ▶ '<' => sub{("$_[0]" + 0) < ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
22 1 ▶ '<=' => sub{("$_[0]" + 0) <= ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 ▶ '==' => sub{("$_[0]" + 0) == ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
24 1 ▶ '>' => sub{("$_[0]" + 0) > ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 ▶ '>=' => sub{("$_[0]" + 0) >= ($_[1] + 0)},
Subroutine __ANON__: called CC=1 SCAR=0.0
26 1 ▶ 'eq' => sub{"$_[0]" eq "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
27 1 ▶ 'ne' => sub{"$_[0]" ne "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 '~~' => 'explain',
29 fallback => 1,
30 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 # ATTRIBUTES
33  
34 2 attr 'day';
35 2 attr 'month';
36 2 attr 'year';
37 2 attr 'hour';
38 2 attr 'minute';
39 2 attr 'second';
40  
41 # BUILDERS
42  
43 sub build_arg {
44 88 ▶ my ($self, $time) = @_;
Subroutine build_arg: called CC=7 SCAR=23.8
Pod undocumented
45  
46 88 my $data = {};
47 88 my @time = gmtime $time;
48  
49 88 ▶ $data->{day} //= $time[3];
Condition33%1/3
$data->{"day"} //= $time[3]
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"day"} //= $time[3]
$data->{"day"} $time[3]
Truth table33%1/3
A //= B
A= $data->{"day"}B= $time[3]
ABresult
1X1
011
000
50 88 ▶ $data->{hour} //= $time[2];
Condition33%1/3
$data->{"hour"} //= $time[2]
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"hour"} //= $time[2]
$data->{"hour"} $time[2]
Truth table33%1/3
A //= B
A= $data->{"hour"}B= $time[2]
ABresult
1X1
011
000
51 88 ▶ $data->{minute} //= $time[1];
Condition33%1/3
$data->{"minute"} //= $time[1]
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"minute"} //= $time[1]
$data->{"minute"} $time[1]
Truth table33%1/3
A //= B
A= $data->{"minute"}B= $time[1]
ABresult
1X1
011
000
52 88 ▶ $data->{month} //= $time[4] + 1;
Condition33%1/3
$data->{"month"} //= $time[4] + 1
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"month"} //= $time[4] + 1
$data->{"month"} $time[4] + 1
Truth table33%1/3
A //= B
A= $data->{"month"}B= $time[4] + 1
ABresult
1X1
011
000
53 88 ▶ $data->{second} //= $time[0];
Condition33%1/3
$data->{"second"} //= $time[0]
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"second"} //= $time[0]
$data->{"second"} $time[0]
Truth table33%1/3
A //= B
A= $data->{"second"}B= $time[0]
ABresult
1X1
011
000
54 88 ▶ $data->{year} //= $time[5] + 1900;
Condition33%1/3
$data->{"year"} //= $time[5] + 1900
l!l&&r!l&&!r
0880
MC/DC0%0/2
$data->{"year"} //= $time[5] + 1900
$data->{"year"} $time[5] + 1900
Truth table33%1/3
A //= B
A= $data->{"year"}B= $time[5] + 1900
ABresult
1X1
011
000
55  
56 88 return $data;
57 }
58  
59 sub build_args {
60 89 ▶ my ($self, $data) = @_;
Subroutine build_args: called CC=7 SCAR=20.2
Pod undocumented
61  
62 89 my @time = gmtime time;
63  
64 89 ▶ $data->{day} //= $time[3];
Condition66%2/3
$data->{"day"} //= $time[3]
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"day"} //= $time[3]
$data->{"day"} $time[3]
Truth table66%2/3
A //= B
A= $data->{"day"}B= $time[3]
ABresult
1X1
011
000
65 89 ▶ $data->{hour} //= $time[2];
Condition66%2/3
$data->{"hour"} //= $time[2]
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"hour"} //= $time[2]
$data->{"hour"} $time[2]
Truth table66%2/3
A //= B
A= $data->{"hour"}B= $time[2]
ABresult
1X1
011
000
66 89 ▶ $data->{minute} //= $time[1];
Condition66%2/3
$data->{"minute"} //= $time[1]
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"minute"} //= $time[1]
$data->{"minute"} $time[1]
Truth table66%2/3
A //= B
A= $data->{"minute"}B= $time[1]
ABresult
1X1
011
000
67 89 ▶ $data->{month} //= $time[4] + 1;
Condition66%2/3
$data->{"month"} //= $time[4] + 1
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"month"} //= $time[4] + 1
$data->{"month"} $time[4] + 1
Truth table66%2/3
A //= B
A= $data->{"month"}B= $time[4] + 1
ABresult
1X1
011
000
68 89 ▶ $data->{second} //= $time[0];
Condition66%2/3
$data->{"second"} //= $time[0]
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"second"} //= $time[0]
$data->{"second"} $time[0]
Truth table66%2/3
A //= B
A= $data->{"second"}B= $time[0]
ABresult
1X1
011
000
69 89 ▶ $data->{year} //= $time[5] + 1900;
Condition66%2/3
$data->{"year"} //= $time[5] + 1900
l!l&&r!l&&!r
8810
MC/DC0%0/2
$data->{"year"} //= $time[5] + 1900
$data->{"year"} $time[5] + 1900
Truth table66%2/3
A //= B
A= $data->{"year"}B= $time[5] + 1900
ABresult
1X1
011
000
70  
71 89 return $data;
72 }
73  
74 # METHODS
75  
76 sub add {
77 8 ▶ my ($self, $data) = @_;
Subroutine add: called CC=3 SCAR=11.1
Pod documented
78  
79 8 for my $name (qw(days hours minutes months seconds years)) {
80 48 ▶ if (my $code = $self->can("add_$name")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->can("add_$name")) 48 0 48
81 48 $self->$code($data->{$name});
82 }
83 }
84  
85 8 return $self;
86 }
87  
88 sub add_days {
89 11 ▶ my ($self, $size) = @_;
Subroutine add_days: called CC=3 SCAR=11.0
Pod documented
90  
91 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
74
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
92  
93 11 ▶ $size = ($self->timeseconds->ONE_DAY * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
94  
95 11 return $self->reset($self->epoch + $size);
96 }
97  
98 sub add_hours {
99 11 ▶ my ($self, $size) = @_;
Subroutine add_hours: called CC=3 SCAR=11.0
Pod documented
100  
101 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
102  
103 11 ▶ $size = ($self->timeseconds->ONE_HOUR * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
104  
105 11 return $self->reset($self->epoch + $size);
106 }
107  
108 sub add_hms {
109 3 ▶ my ($self, $h, $m, $s) = @_;
Subroutine add_hms: called CC=4 SCAR=13.9
Pod documented
110  
111 3 my $data = {};
112  
113 3 ▶ $data->{hours} = $h if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 2 1 3
114 3 ▶ $data->{minutes} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 3 0 3
115 3 ▶ $data->{seconds} = $s if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 2 1 3
116  
117 3 return $self->add($data);
118 }
119  
120 sub add_mdy {
121 3 ▶ my ($self, $m, $d, $y) = @_;
Subroutine add_mdy: called CC=4 SCAR=13.9
Pod documented
122  
123 3 my $data = {};
124  
125 3 ▶ $data->{days} = $d if defined $d;
Branch: 1 branch
BranchTrueFalseTotal
if defined $d 3 0 3
126 3 ▶ $data->{months} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 2 1 3
127 3 ▶ $data->{years} = $y if defined $y;
Branch: 1 branch
BranchTrueFalseTotal
if defined $y 2 1 3
128  
129 3 return $self->add($data);
130 }
131  
132 sub add_minutes {
133 11 ▶ my ($self, $size) = @_;
Subroutine add_minutes: called CC=3 SCAR=11.0
Pod documented
134  
135 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
74
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
136  
137 11 ▶ $size = ($self->timeseconds->ONE_MINUTE * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
138  
139 11 return $self->reset($self->epoch + $size);
140 }
141  
142 sub add_months {
143 11 ▶ my ($self, $size) = @_;
Subroutine add_months: called CC=3 SCAR=11.0
Pod documented
144  
145 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
146  
147 11 ▶ $size = ($self->timeseconds->ONE_MONTH * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
148  
149 11 return $self->reset($self->epoch + $size);
150 }
151  
152 sub add_seconds {
153 11 ▶ my ($self, $size) = @_;
Subroutine add_seconds: called CC=2 SCAR=6.9
Pod documented
154  
155 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
156  
157 11 return $self->reset($self->epoch + $size);
158 }
159  
160 sub add_years {
161 11 ▶ my ($self, $size) = @_;
Subroutine add_years: called CC=3 SCAR=11.0
Pod documented
162  
163 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
164  
165 11 ▶ $size = ($self->timeseconds->ONE_YEAR * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 5 6 11
166  
167 11 return $self->reset($self->epoch + $size);
168 }
169  
170 sub epoch {
171 339 ▶ my ($self) = @_;
Subroutine epoch: called CC=1 SCAR=0.0
Pod documented
172  
173 339 return $self->timepiece->epoch;
174 }
175  
176 sub explain {
177 13 ▶ my ($self) = @_;
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
178  
179 13 return $self->epoch;
180 }
181  
182 sub format {
183 4 ▶ my ($self, @args) = @_;
Subroutine format: called CC=1 SCAR=0.0
Pod documented
184  
185 4 return $self->timepiece->strftime(@args);
186 }
187  
188 sub hms {
189 1 ▶ my ($self) = @_;
Subroutine hms: called CC=1 SCAR=0.0
Pod documented
190  
191 1 return $self->timepiece->hms;
192 }
193  
194 sub iso8601 {
195 3 ▶ my ($self) = @_;
Subroutine iso8601: called CC=1 SCAR=0.0
Pod documented
196  
197 3 return $self->timepiece->datetime;
198 }
199  
200 sub mdy {
201 1 ▶ my ($self) = @_;
Subroutine mdy: called CC=1 SCAR=0.0
Pod documented
202  
203 1 return $self->timepiece->mdy;
204 }
205  
206 sub parse {
207 1 ▶ my ($self, @args) = @_;
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
208  
209 1 my $timepiece = $self->timepiece->strptime(@args);
210  
211 1 return $self->reset($timepiece->epoch);
212 }
213  
214 sub reset {
215 134 ▶ my ($self, $time) = @_;
Subroutine reset: called CC=2 SCAR=7.0
Pod documented
216  
217 134 ▶ $time ||= time;
Condition33%1/3
$time ||= time
l!l&&r!l&&!r
13400
MC/DC0%0/2
$time ||= time
$time time
Truth table33%1/3
A ||= B
A= $timeB= time
ABresult
1X1
011
000
218  
219 134 my @time = gmtime $time;
220  
221 134 $self->day($time[3]);
222 134 $self->hour($time[2]);
223 134 $self->minute($time[1]);
224 134 $self->month($time[4] + 1);
225 134 $self->second($time[0]);
226 134 $self->year($time[5] + 1900);
227  
228 134 return $self;
229 }
230  
231 sub restart {
232 0 ▶ my ($self, $here) = @_;
Subroutine restart: not called CC=1 SCAR=6.9
Pod documented
233  
234 0 my $timepiece = $self->timepiece->truncate(to => $here);
235  
236 0 return $self->reset($timepiece->epoch);
237 }
238  
239 sub rfc822 {
240 1 ▶ my ($self) = @_;
Subroutine rfc822: called CC=1 SCAR=0.0
Pod undocumented
241  
242 1 return $self->format('%a, %d %b %Y %H:%M:%S %z');
243 }
244  
245 sub rfc1123 {
246 1 ▶ my ($self) = @_;
Subroutine rfc1123: called CC=1 SCAR=0.0
Pod undocumented
247  
248 1 return $self->format('%a, %d %b %Y %T GMT');
249 }
250  
251 sub rfc3339 {
252 2 ▶ my ($self) = @_;
Subroutine rfc3339: called CC=1 SCAR=0.0
Pod documented
253  
254 2 return "@{[$self->iso8601]}Z";
255 }
256  
257 sub rfc7231 {
258 1 ▶ my ($self) = @_;
Subroutine rfc7231: called CC=1 SCAR=0.0
Pod documented
259  
260 1 return $self->timepiece->strftime;
261 }
262  
263 sub set {
264 9 ▶ my ($self, $data) = @_;
Subroutine set: called CC=3 SCAR=11.0
Pod documented
265  
266 9 for my $name (qw(day hour minute month second year)) {
267 54 ▶ if (defined $data->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{$name}) 22 32 54
268 22 $self->$name($data->{$name});
269 }
270 }
271  
272 9 return $self;
273 }
274  
275 sub set_hms {
276 3 ▶ my ($self, $h, $m, $s) = @_;
Subroutine set_hms: called CC=4 SCAR=14.0
Pod documented
277  
278 3 my $data = {};
279  
280 3 ▶ $data->{hour} = $h if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 2 1 3
281 3 ▶ $data->{minute} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 3 0 3
282 3 ▶ $data->{second} = $s if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 3 0 3
283  
284 3 return $self->set($data);
285 }
286  
287 sub set_mdy {
288 3 ▶ my ($self, $m, $d, $y) = @_;
Subroutine set_mdy: called CC=4 SCAR=13.9
Pod documented
289  
290 3 my $data = {};
291  
292 3 ▶ $data->{day} = $d if defined $d;
Branch: 1 branch
BranchTrueFalseTotal
if defined $d 3 0 3
293 3 ▶ $data->{month} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 2 1 3
294 3 ▶ $data->{year} = $y if defined $y;
Branch: 1 branch
BranchTrueFalseTotal
if defined $y 1 2 3
295  
296 3 return $self->set($data);
297 }
298  
299 sub string {
300 1 ▶ my ($self) = @_;
Subroutine string: called CC=1 SCAR=0.0
Pod documented
301  
302 1 return $self->rfc3339;
303 }
304  
305 sub sub {
306 8 ▶ my ($self, $data) = @_;
Subroutine sub: called CC=3 SCAR=11.1
Pod documented
307  
308 8 for my $name (qw(days hours minutes months seconds years)) {
309 48 ▶ if (my $code = $self->can("sub_$name")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->can("sub_$name")) 48 0 48
310 48 $self->$code($data->{$name});
311 }
312 }
313  
314 8 return $self;
315 }
316  
317 sub sub_days {
318 11 ▶ my ($self, $size) = @_;
Subroutine sub_days: called CC=3 SCAR=11.0
Pod documented
319  
320 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
74
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
321  
322 11 ▶ $size = ($self->timeseconds->ONE_DAY * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 7 4 11
323  
324 11 return $self->reset($self->epoch - $size);
325 }
326  
327 sub sub_hours {
328 11 ▶ my ($self, $size) = @_;
Subroutine sub_hours: called CC=3 SCAR=11.0
Pod documented
329  
330 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
331  
332 11 ▶ $size = ($self->timeseconds->ONE_HOUR * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
333  
334 11 return $self->reset($self->epoch - $size);
335 }
336  
337 sub sub_hms {
338 3 ▶ my ($self, $h, $m, $s) = @_;
Subroutine sub_hms: called CC=4 SCAR=13.9
Pod documented
339  
340 3 my $data = {};
341  
342 3 ▶ $data->{hours} = $h if defined $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 2 1 3
343 3 ▶ $data->{minutes} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 3 0 3
344 3 ▶ $data->{seconds} = $s if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 2 1 3
345  
346 3 return $self->sub($data);
347 }
348  
349 sub sub_mdy {
350 3 ▶ my ($self, $m, $d, $y) = @_;
Subroutine sub_mdy: called CC=4 SCAR=14.0
Pod documented
351  
352 3 my $data = {};
353  
354 3 ▶ $data->{days} = $d if defined $d;
Branch: 1 branch
BranchTrueFalseTotal
if defined $d 3 0 3
355 3 ▶ $data->{months} = $m if defined $m;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m 3 0 3
356 3 ▶ $data->{years} = $y if defined $y;
Branch: 1 branch
BranchTrueFalseTotal
if defined $y 1 2 3
357  
358 3 return $self->sub($data);
359 }
360  
361 sub sub_minutes {
362 11 ▶ my ($self, $size) = @_;
Subroutine sub_minutes: called CC=3 SCAR=11.0
Pod documented
363  
364 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
74
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
365  
366 11 ▶ $size = ($self->timeseconds->ONE_MINUTE * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 6 5 11
367  
368 11 return $self->reset($self->epoch - $size);
369 }
370  
371 sub sub_months {
372 11 ▶ my ($self, $size) = @_;
Subroutine sub_months: called CC=3 SCAR=11.0
Pod documented
373  
374 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
74
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
375  
376 11 ▶ $size = ($self->timeseconds->ONE_MONTH * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 7 4 11
377  
378 11 return $self->reset($self->epoch - $size);
379 }
380  
381 sub sub_seconds {
382 11 ▶ my ($self, $size) = @_;
Subroutine sub_seconds: called CC=2 SCAR=6.9
Pod documented
383  
384 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
65
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
385  
386 11 return $self->reset($self->epoch - $size);
387 }
388  
389 sub sub_years {
390 11 ▶ my ($self, $size) = @_;
Subroutine sub_years: called CC=3 SCAR=11.0
Pod documented
391  
392 11 ▶ $size //= 0;
Condition100%2/2
$size //= 0
l!l
56
MC/DC100%1/1
$size //= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
393  
394 11 ▶ $size = ($self->timeseconds->ONE_YEAR * $size) if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 5 6 11
395  
396 11 return $self->reset($self->epoch - $size);
397 }
398  
399 sub timelocal {
400 350 ▶ my ($self) = @_;
Subroutine timelocal: called CC=1 SCAR=0.0
Pod undocumented
401  
402 350 require Time::Local;
403  
404 350 my $day = $self->day;
405 350 my $hour = $self->hour;
406 350 my $minute = $self->minute;
407 350 my $month = $self->month - 1;
408 350 my $second = $self->second;
409 350 my $year = $self->year;
410  
411 350 return Time::Local::timegm($second, $minute, $hour, $day, $month, $year);
412 }
413  
414 sub timepiece {
415 350 ▶ my ($self) = @_;
Subroutine timepiece: called CC=1 SCAR=0.0
Pod undocumented
416  
417 350 require Time::Piece;
418  
419 350 return Time::Piece->gmtime(0 + $self->timelocal);
420 }
421  
422 sub timeseconds {
423 60 ▶ my ($self, $time) = @_;
Subroutine timeseconds: called CC=2 SCAR=7.1
Pod undocumented
424  
425 60 require Time::Seconds;
426  
427 60 ▶ return Time::Seconds->new($time // 0);
Condition50%1/2
$time // 0
l!l
060
MC/DC0%0/1
$time // 0
$time
Truth table50%1/2
A
A= $time
Aresult
11
00
428 }
429  
430 sub truncate_to_day {
431 0 ▶ my ($self) = @_;
Subroutine truncate_to_day: not called CC=1 SCAR=6.9
Pod documented
432  
433 0 return $self->restart('day');
434 }
435  
436 sub truncate_to_hour {
437 0 ▶ my ($self) = @_;
Subroutine truncate_to_hour: not called CC=1 SCAR=6.9
Pod documented
438  
439 0 return $self->restart('hour');
440 }
441  
442 sub truncate_to_minute {
443 0 ▶ my ($self) = @_;
Subroutine truncate_to_minute: not called CC=1 SCAR=6.9
Pod documented
444  
445 0 return $self->restart('minute');
446 }
447  
448 sub truncate_to_month {
449 0 ▶ my ($self) = @_;
Subroutine truncate_to_month: not called CC=1 SCAR=6.9
Pod documented
450  
451 0 return $self->restart('month');
452 }
453  
454 sub truncate_to_quarter {
455 0 ▶ my ($self) = @_;
Subroutine truncate_to_quarter: not called CC=1 SCAR=6.9
Pod documented
456  
457 0 return $self->restart('quarter');
458 }
459  
460 sub truncate_to_second {
461 0 ▶ my ($self) = @_;
Subroutine truncate_to_second: not called CC=1 SCAR=6.9
Pod documented
462  
463 0 return $self->restart('second');
464 }
465  
466 sub truncate_to_year {
467 0 ▶ my ($self) = @_;
Subroutine truncate_to_year: not called CC=1 SCAR=6.9
Pod documented
468  
469 0 return $self->restart('year');
470 }
471  
472 2 1;
473  
474  
475  
476 =head1 NAME
477  
478 Venus::Date - Date Class
479  
480 =cut
481  
482 =head1 ABSTRACT
483  
484 Date Class for Perl 5
485  
486 =cut
487  
488 =head1 SYNOPSIS
489  
490 package main;
491  
492 use Venus::Date;
493  
494 my $date = Venus::Date->new(570672000);
495  
496 # $date->string;
497  
498 # '1988-02-01T00:00:00Z'
499  
500 =cut
501  
502 =head1 DESCRIPTION
503  
504 This package provides methods for formatting, parsing, and manipulating date
505 and time data.
506  
507 =cut
508  
509 =head1 ATTRIBUTES
510  
511 This package has the following attributes:
512  
513 =cut
514  
515 =head2 day
516  
517 day(Int)
518  
519 This attribute is read-write, accepts C<(Int)> values, and is optional.
520  
521 =cut
522  
523 =head2 month
524  
525 month(Int)
526  
527 This attribute is read-write, accepts C<(Int)> values, and is optional.
528  
529 =cut
530  
531 =head2 year
532  
533 year(Int)
534  
535 This attribute is read-write, accepts C<(Int)> values, and is optional.
536  
537 =cut
538  
539 =head2 hour
540  
541 hour(Int)
542  
543 This attribute is read-write, accepts C<(Int)> values, and is optional.
544  
545 =cut
546  
547 =head2 minute
548  
549 minute(Int)
550  
551 This attribute is read-write, accepts C<(Int)> values, and is optional.
552  
553 =cut
554  
555 =head2 second
556  
557 second(Int)
558  
559 This attribute is read-write, accepts C<(Int)> values, and is optional.
560  
561 =cut
562  
563 =head1 INHERITS
564  
565 This package inherits behaviors from:
566  
567 L<Venus::Kind::Utility>
568  
569 =cut
570  
571 =head1 INTEGRATES
572  
573 This package integrates behaviors from:
574  
575 L<Venus::Role::Buildable>
576  
577 L<Venus::Role::Explainable>
578  
579 =cut
580  
581 =head1 METHODS
582  
583 This package provides the following methods:
584  
585 =cut
586  
587 =head2 add
588  
589 add(HashRef $data) (Date)
590  
591 The add method increments the date and time attributes specified.
592  
593 I<Since C<0.01>>
594  
595 =over 4
596  
597 =item add example 1
598  
599 # given: synopsis;
600  
601 $date = $date->add({
602 days => 1,
603 months => 1,
604 years => 1,
605 });
606  
607 # $date->string; # 1989-03-03T16:17:54Z
608  
609 # $date->epoch; # 604945074
610  
611  
612  
613  
614 =back
615  
616 =over 4
617  
618 =item add example 2
619  
620 # given: synopsis;
621  
622 $date = $date->add({
623 hours => 1,
624 minutes => 1,
625 seconds => 1,
626 });
627  
628 # $date->string; # 1988-02-01T01:01:01Z
629  
630 # $date->epoch; # 570675661
631  
632 =back
633  
634 =cut
635  
636 =head2 add_days
637  
638 add_days(Int $days) (Any)
639  
640 The add_days method increments the C<day> attribute.
641  
642 I<Since C<0.01>>
643  
644 =over 4
645  
646 =item add_days example 1
647  
648 # given: synopsis;
649  
650 $date = $date->add_days(1);
651  
652 # $date->string; # 1988-02-02T00:00:00Z
653  
654 # $date->epoch; # 570758400
655  
656 =back
657  
658 =over 4
659  
660 =item add_days example 2
661  
662 # given: synopsis;
663  
664 $date = $date->add_days(40);
665  
666 # $date->string; # 1988-03-12T00:00:00Z
667  
668 # $date->epoch; # 574128000
669  
670 =back
671  
672 =over 4
673  
674 =item add_days example 3
675  
676 # given: synopsis;
677  
678 $date = $date->add_days(-1);
679  
680 # $date->string; # 1988-01-31T00:00:00Z
681  
682 # $date->epoch; # 570585600
683  
684 =back
685  
686 =cut
687  
688 =head2 add_hms
689  
690 add_hms(Maybe[Int] $hours, Maybe[Int] $minutes, Maybe[Int] $seconds) (Date)
691  
692 The add_hms method increments the C<hour>, C<minute>, and C<second> attributes.
693  
694 I<Since C<0.01>>
695  
696 =over 4
697  
698 =item add_hms example 1
699  
700 # given: synopsis;
701  
702 $date = $date->add_hms(1, 0, 0);
703  
704 # $date->string; # 1988-02-01T01:00:00Z
705  
706 # $date->epoch; # 570675600
707  
708 =back
709  
710 =over 4
711  
712 =item add_hms example 2
713  
714 # given: synopsis;
715  
716 $date = $date->add_hms(undef, 1, 1);
717  
718 # $date->string; # 1988-02-01T00:01:01Z
719  
720 # $date->epoch; # 570672061
721  
722 =back
723  
724 =over 4
725  
726 =item add_hms example 3
727  
728 # given: synopsis;
729  
730 $date = $date->add_hms(1, 1);
731  
732 # $date->string; # 1988-02-01T01:01:00Z
733  
734 # $date->epoch; # 570675660
735  
736 =back
737  
738 =cut
739  
740 =head2 add_hours
741  
742 add_hours(Int $hours) (Any)
743  
744 The add_hours method increments the C<hour> attribute.
745  
746 I<Since C<0.01>>
747  
748 =over 4
749  
750 =item add_hours example 1
751  
752 # given: synopsis;
753  
754 $date = $date->add_hours(1);
755  
756 # $date->string; # 1988-02-01T01:00:00Z
757  
758 # $date->epoch; # 570675600
759  
760 =back
761  
762 =over 4
763  
764 =item add_hours example 2
765  
766 # given: synopsis;
767  
768 $date = $date->add_hours(25);
769  
770 # $date->string; # 1988-02-02T01:00:00Z
771  
772 # $date->epoch; # 570762000
773  
774 =back
775  
776 =over 4
777  
778 =item add_hours example 3
779  
780 # given: synopsis;
781  
782 $date = $date->add_hours(-1);
783  
784 # $date->string; # 1988-01-31T23:00:00Z
785  
786 # $date->epoch; # 570668400
787  
788 =back
789  
790 =cut
791  
792 =head2 add_mdy
793  
794 add_mdy(Maybe[Int] $months, Maybe[Int] $days, Maybe[Int] $years) (Date)
795  
796 The add_mdy method increments the C<month>, C<day>, and C<years> attributes.
797  
798 I<Since C<0.01>>
799  
800 =over 4
801  
802 =item add_mdy example 1
803  
804 # given: synopsis;
805  
806 $date = $date->add_mdy(1, 0, 0);
807  
808 # $date->string; # 1988-03-02T10:29:04Z
809  
810 # $date->epoch; # 573301744
811  
812 =back
813  
814 =over 4
815  
816 =item add_mdy example 2
817  
818 # given: synopsis;
819  
820 $date = $date->add_mdy(undef, 1, 1);
821  
822 # $date->string; # 1989-02-01T05:48:50Z
823  
824 # $date->epoch; # 602315330
825  
826 =back
827  
828 =over 4
829  
830 =item add_mdy example 3
831  
832 # given: synopsis;
833  
834 $date = $date->add_mdy(1, 1);
835  
836 # $date->string; # 1988-03-03T10:29:04Z
837  
838 # $date->epoch; # 573388144
839  
840 =back
841  
842 =cut
843  
844 =head2 add_minutes
845  
846 add_minutes(Int $minutes) (Date)
847  
848 The add_minutes method increments the C<minute> attribute.
849  
850 I<Since C<0.01>>
851  
852 =over 4
853  
854 =item add_minutes example 1
855  
856 # given: synopsis;
857  
858 $date = $date->add_minutes(1);
859  
860 # $date->string; # 1988-02-01T00:01:00Z
861  
862 # $date->epoch; # 570672060
863  
864 =back
865  
866 =over 4
867  
868 =item add_minutes example 2
869  
870 # given: synopsis;
871  
872 $date = $date->add_minutes(61);
873  
874 # $date->string; # 1988-02-01T01:01:00Z
875  
876 # $date->epoch; # 570675660
877  
878 =back
879  
880 =over 4
881  
882 =item add_minutes example 3
883  
884 # given: synopsis;
885  
886 $date = $date->add_minutes(-1);
887  
888 # $date->string; # 1988-01-31T23:59:00Z
889  
890 # $date->epoch; # 570671940
891  
892 =back
893  
894 =cut
895  
896 =head2 add_months
897  
898 add_months(Int $months) (Date)
899  
900 The add_months method increments the C<month> attribute.
901  
902 I<Since C<0.01>>
903  
904 =over 4
905  
906 =item add_months example 1
907  
908 # given: synopsis;
909  
910 $date = $date->add_months(1);
911  
912 # $date->string; # 1988-03-02T10:29:04Z
913  
914 # $date->epoch; # 573301744
915  
916 =back
917  
918 =over 4
919  
920 =item add_months example 2
921  
922 # given: synopsis;
923  
924 $date = $date->add_months(13);
925  
926 # $date->string; # 1989-03-02T16:17:52Z
927  
928 # $date->epoch; # 604858672
929  
930 =back
931  
932 =over 4
933  
934 =item add_months example 3
935  
936 # given: synopsis;
937  
938 $date = $date->add_months(-1);
939  
940 # $date->string; # 1988-01-01T13:30:56Z
941  
942 # $date->epoch; # 568042256
943  
944 =back
945  
946 =cut
947  
948 =head2 add_seconds
949  
950 add_seconds(Int $seconds) (Date)
951  
952 The add_seconds method increments the C<second> attribute.
953  
954 I<Since C<0.01>>
955  
956 =over 4
957  
958 =item add_seconds example 1
959  
960 # given: synopsis;
961  
962 $date = $date->add_seconds(1);
963  
964 # $date->string; # 1988-02-01T00:00:01Z
965  
966 # $date->epoch; # 570672001
967  
968 =back
969  
970 =over 4
971  
972 =item add_seconds example 2
973  
974 # given: synopsis;
975  
976 $date = $date->add_seconds(61);
977  
978 # $date->string; # 1988-02-01T00:01:01Z
979  
980 # $date->epoch; # 570672061
981  
982 =back
983  
984 =over 4
985  
986 =item add_seconds example 3
987  
988 # given: synopsis;
989  
990 $date = $date->add_seconds(-1);
991  
992 # $date->string; # 1988-01-31T23:59:59Z
993  
994 # $date->epoch; # 570671999
995  
996 =back
997  
998 =cut
999  
1000 =head2 add_years
1001  
1002 add_years(Int $years) (Date)
1003  
1004 The add_years method increments the C<year> attribute.
1005  
1006 I<Since C<0.01>>
1007  
1008 =over 4
1009  
1010 =item add_years example 1
1011  
1012 # given: synopsis;
1013  
1014 $date = $date->add_years(1);
1015  
1016 # $date->string; # 1989-01-31T05:48:50Z
1017  
1018 # $date->epoch; # 602228930
1019  
1020 =back
1021  
1022 =over 4
1023  
1024 =item add_years example 2
1025  
1026 # given: synopsis;
1027  
1028 $date = $date->add_years(50);
1029  
1030 # $date->string; # 2038-01-31T02:41:40Z
1031  
1032 # $date->epoch; # 2148518500
1033  
1034 =back
1035  
1036 =over 4
1037  
1038 =item add_years example 3
1039  
1040 # given: synopsis;
1041  
1042 $date = $date->add_years(-1);
1043  
1044 # $date->string; # 1987-01-31T18:11:10Z
1045  
1046 # $date->epoch; # 539115070
1047  
1048 =back
1049  
1050 =cut
1051  
1052 =head2 epoch
1053  
1054 epoch() (Int)
1055  
1056 The epoch method returns the epoch.
1057  
1058 I<Since C<0.01>>
1059  
1060 =over 4
1061  
1062 =item epoch example 1
1063  
1064 # given: synopsis;
1065  
1066 my $epoch = $date->epoch;
1067  
1068 # 570672000
1069  
1070 =back
1071  
1072 =cut
1073  
1074 =head2 explain
1075  
1076 explain() (Int)
1077  
1078 The explain method returns the epoch and is used in stringification operations.
1079  
1080 I<Since C<0.01>>
1081  
1082 =over 4
1083  
1084 =item explain example 1
1085  
1086 # given: synopsis;
1087  
1088 my $explain = $date->explain;
1089  
1090 # 570672000
1091  
1092 =back
1093  
1094 =cut
1095  
1096 =head2 format
1097  
1098 format(Str $format) (Str)
1099  
1100 The format method returns the formatted date and time string. See
1101 L<strftime|http://www.unix.com/man-page/FreeBSD/3/strftime/> for formatting
1102 rules.
1103  
1104 I<Since C<0.01>>
1105  
1106 =over 4
1107  
1108 =item format example 1
1109  
1110 # given: synopsis;
1111  
1112 my $format = $date->format('%A, %B %e, %Y');
1113  
1114 # Monday, February 1, 1988
1115  
1116 =back
1117  
1118 =over 4
1119  
1120 =item format example 2
1121  
1122 # given: synopsis;
1123  
1124 my $format = $date->format('%b %e %a');
1125  
1126 # Feb 1 Mon
1127  
1128 =back
1129  
1130 =cut
1131  
1132 =head2 hms
1133  
1134 hms() (Str)
1135  
1136 The hms method returns the time formatted as C<hh:mm:ss>.
1137  
1138 I<Since C<0.01>>
1139  
1140 =over 4
1141  
1142 =item hms example 1
1143  
1144 # given: synopsis;
1145  
1146 my $hms = $date->hms;
1147  
1148 # 00:00:00
1149  
1150 =back
1151  
1152 =cut
1153  
1154 =head2 iso8601
1155  
1156 iso8601() (Str)
1157  
1158 The iso8601 method returns the date and time formatted as an ISO8601 string.
1159  
1160 I<Since C<0.01>>
1161  
1162 =over 4
1163  
1164 =item iso8601 example 1
1165  
1166 # given: synopsis;
1167  
1168 my $iso8601 = $date->iso8601;
1169  
1170 # 1988-02-01T00:00:00
1171  
1172 =back
1173  
1174 =cut
1175  
1176 =head2 mdy
1177  
1178 mdy() (Str)
1179  
1180 The mdy method returns the date formatted as C<mm-dd-yyyy>.
1181  
1182 I<Since C<0.01>>
1183  
1184 =over 4
1185  
1186 =item mdy example 1
1187  
1188 # given: synopsis;
1189  
1190 my $mdy = $date->mdy;
1191  
1192 # 02-01-1988
1193  
1194 =back
1195  
1196 =cut
1197  
1198 =head2 parse
1199  
1200 parse(Any @data) (Date)
1201  
1202 The parse method resets and returns a date object based on the parsed time
1203 provided. See L<strptime|http://www.unix.com/man-page/FreeBSD/3/strptime/> for
1204 parsing rules.
1205  
1206 I<Since C<0.01>>
1207  
1208 =over 4
1209  
1210 =item parse example 1
1211  
1212 # given: synopsis;
1213  
1214 $date = $date->parse('Monday, February 1, 1988', '%A, %B %e, %Y');
1215  
1216 # $date->string; # 1988-02-01T00:00:00Z
1217  
1218 # $date->epoch; # 570672000
1219  
1220 =back
1221  
1222 =cut
1223  
1224 =head2 reset
1225  
1226 reset(Int $time) (Date)
1227  
1228 The reset method resets all attributes to correspond with the epoch provided.
1229  
1230 I<Since C<0.01>>
1231  
1232 =over 4
1233  
1234 =item reset example 1
1235  
1236 # given: synopsis;
1237  
1238 $date = $date->reset(631152000);
1239  
1240 # $date->string; # 1990-01-01T00:00:00Z
1241  
1242 # $date->epoch; # 631152000
1243  
1244 =back
1245  
1246 =cut
1247  
1248 =head2 restart
1249  
1250 restart(Str $interval) (Date)
1251  
1252 The restart method truncates the date and time to the specified unit of time,
1253 e.g. C<year>, C<quarter>, C<month>, C<day>, C<hour>, C<minute>, C<second>.
1254  
1255 I<Since C<0.01>>
1256  
1257 =over 4
1258  
1259 =item restart example 1
1260  
1261 # given: synopsis;
1262  
1263 $date = $date->restart('year');
1264  
1265 # $date->string; # 1988-01-01T00:00:00Z
1266  
1267 # $date->epoch; # 567993600
1268  
1269 =back
1270  
1271 =over 4
1272  
1273 =item restart example 2
1274  
1275 # given: synopsis;
1276  
1277 $date = $date->restart('quarter');
1278  
1279 # $date->string; # 1988-01-01T00:00:00Z
1280  
1281 # $date->epoch; # 567993600
1282  
1283 =back
1284  
1285 =over 4
1286  
1287 =item restart example 3
1288  
1289 # given: synopsis;
1290  
1291 $date = $date->restart('month');
1292  
1293 # $date->string; # 1988-02-01T00:00:00Z
1294  
1295 # $date->epoch; # 570672000
1296  
1297 =back
1298  
1299 =cut
1300  
1301 =head2 rfc3339
1302  
1303 rfc3339() (Str)
1304  
1305 The rfc3339 method returns the date and time formatted as an RFC3339 string.
1306  
1307 I<Since C<0.01>>
1308  
1309 =over 4
1310  
1311 =item rfc3339 example 1
1312  
1313 # given: synopsis;
1314  
1315 my $rfc3339 = $date->rfc3339;
1316  
1317 # 1988-02-01T00:00:00Z
1318  
1319 =back
1320  
1321 =cut
1322  
1323 =head2 rfc7231
1324  
1325 rfc7231() (Str)
1326  
1327 The rfc7231 method returns the date and time formatted as an RFC7231 string.
1328  
1329 I<Since C<0.01>>
1330  
1331 =over 4
1332  
1333 =item rfc7231 example 1
1334  
1335 # given: synopsis;
1336  
1337 my $rfc7231 = $date->rfc7231;
1338  
1339 # Mon, 01 Feb 1988 00:00:00 UTC
1340  
1341 =back
1342  
1343 =cut
1344  
1345 =head2 set
1346  
1347 set(HashRef $data) (Date)
1348  
1349 The set method sets the date and time attributes specified.
1350  
1351 I<Since C<0.01>>
1352  
1353 =over 4
1354  
1355 =item set example 1
1356  
1357 # given: synopsis;
1358  
1359 $date = $date->set({
1360 day => 1,
1361 month => 1,
1362 year => 2000,
1363 });
1364  
1365 # $date->string; # 2000-01-01T00:00:00Z
1366  
1367 # $date->epoch; # 946684800
1368  
1369 =back
1370  
1371 =over 4
1372  
1373 =item set example 2
1374  
1375 # given: synopsis;
1376  
1377 $date = $date->set({
1378 day => 1,
1379 month => 12,
1380 });
1381  
1382 # $date->string; # 1988-12-01T00:00:00Z
1383  
1384 # $date->epoch; # 596937600
1385  
1386 =back
1387  
1388 =over 4
1389  
1390 =item set example 3
1391  
1392 # given: synopsis;
1393  
1394 $date = $date->set({
1395 day => 1,
1396 month => 12,
1397 year => 1979,
1398 });
1399  
1400 # $date->string; # 1979-12-01T00:00:00Z
1401  
1402 # $date->epoch; # 312854400
1403  
1404 =back
1405  
1406 =cut
1407  
1408 =head2 set_hms
1409  
1410 set_hms(Maybe[Int] $hours, Maybe[Int] $minutes, Maybe[Int] $seconds) (Date)
1411  
1412 The set_hms method sets the C<hour>, C<minute>, and C<second> attributes.
1413  
1414 I<Since C<0.01>>
1415  
1416 =over 4
1417  
1418 =item set_hms example 1
1419  
1420 # given: synopsis;
1421  
1422 $date = $date->set_hms(1, 0, 0);
1423  
1424 # $date->string; # 1988-02-01T01:00:00Z
1425  
1426 # $date->epoch; # 570675600
1427  
1428 =back
1429  
1430 =over 4
1431  
1432 =item set_hms example 2
1433  
1434 # given: synopsis;
1435  
1436 $date = $date->set_hms(undef, 30, 30);
1437  
1438 # $date->string; # 1988-02-01T00:30:30Z
1439  
1440 # $date->epoch; # 570673830
1441  
1442 =back
1443  
1444 =over 4
1445  
1446 =item set_hms example 3
1447  
1448 # given: synopsis;
1449  
1450 $date = $date->set_hms(0, 59, 59);
1451  
1452 # $date->string; # 1988-02-01T00:59:59Z
1453  
1454 # $date->epoch; # 570675599
1455  
1456 =back
1457  
1458 =cut
1459  
1460 =head2 set_mdy
1461  
1462 set_mdy(Maybe[Int] $months, Maybe[Int] $days, Maybe[Int] $years) (Date)
1463  
1464 The set_mdy method sets the C<month>, C<day>, and C<year> attributes.
1465  
1466  
1467  
1468  
1469 I<Since C<0.01>>
1470  
1471 =over 4
1472  
1473 =item set_mdy example 1
1474  
1475 # given: synopsis;
1476  
1477 $date = $date->set_mdy(4, 30, 1990);
1478  
1479 # $date->string; # 1990-04-30T00:00:00Z
1480  
1481 # $date->epoch; # 641433600
1482  
1483 =back
1484  
1485 =over 4
1486  
1487 =item set_mdy example 2
1488  
1489 # given: synopsis;
1490  
1491 $date = $date->set_mdy(4, 30, undef);
1492  
1493 # $date->string; # 1988-04-30T00:00:00Z
1494  
1495 # $date->epoch; # 578361600
1496  
1497 =back
1498  
1499 =over 4
1500  
1501 =item set_mdy example 3
1502  
1503 # given: synopsis;
1504  
1505 $date = $date->set_mdy(undef, 15, undef);
1506  
1507 # $date->string; # 1988-02-15T00:00:00Z
1508  
1509 # $date->epoch; # 571881600
1510  
1511 =back
1512  
1513 =cut
1514  
1515 =head2 string
1516  
1517 string() (Str)
1518  
1519 The string method returns a date and time string, and is an alias for
1520 L</rfc3339>.
1521  
1522 I<Since C<0.01>>
1523  
1524 =over 4
1525  
1526 =item string example 1
1527  
1528 # given: synopsis;
1529  
1530 my $string = $date->string;
1531  
1532 # 1988-02-01T00:00:00Z
1533  
1534 =back
1535  
1536 =cut
1537  
1538 =head2 sub
1539  
1540 sub(HashRef $data) (Date)
1541  
1542 The sub method method decrements the date and time attributes specified.
1543  
1544 I<Since C<0.01>>
1545  
1546 =over 4
1547  
1548 =item sub example 1
1549  
1550 # given: synopsis;
1551  
1552 $date = $date->sub({
1553 days => 1,
1554 months => 1,
1555 years => 1,
1556 });
1557  
1558 # $date->string; # 1986-12-31T07:42:06Z
1559  
1560 # $date->epoch; # 536398926
1561  
1562 =back
1563  
1564 =over 4
1565  
1566 =item sub example 2
1567  
1568 # given: synopsis;
1569  
1570 $date = $date->sub({
1571 hours => 1,
1572 minutes => 1,
1573 seconds => 1,
1574 });
1575  
1576 # $date->string; # 1988-01-31T22:58:59Z
1577  
1578 # $date->epoch; # 570668339
1579  
1580 =back
1581  
1582 =cut
1583  
1584 =head2 sub_days
1585  
1586 sub_days(Int $days) (Date)
1587  
1588 The sub_days method decrements the C<day> attribute.
1589  
1590 I<Since C<0.01>>
1591  
1592 =over 4
1593  
1594 =item sub_days example 1
1595  
1596 # given: synopsis;
1597  
1598 $date = $date->sub_days(1);
1599  
1600 # $date->string; # 1988-01-31T00:00:00Z
1601  
1602 # $date->epoch; # 570585600
1603  
1604 =back
1605  
1606 =over 4
1607  
1608 =item sub_days example 2
1609  
1610 # given: synopsis;
1611  
1612 $date = $date->sub_days(32);
1613  
1614 # $date->string; # 1987-12-31T00:00:00Z
1615  
1616 # $date->epoch; # 567907200
1617  
1618 =back
1619  
1620 =over 4
1621  
1622 =item sub_days example 3
1623  
1624 # given: synopsis;
1625  
1626 $date = $date->sub_days(-1);
1627  
1628 # $date->string; # 1988-02-02T00:00:00Z
1629  
1630 # $date->epoch; # 570758400
1631  
1632 =back
1633  
1634 =cut
1635  
1636 =head2 sub_hms
1637  
1638 sub_hms(Maybe[Int] $hours, Maybe[Int] $minutes, Maybe[Int] $seconds) (Date)
1639  
1640 The sub_hms method decrements the C<hour>, C<minute>, and C<second> attributes.
1641  
1642 I<Since C<0.01>>
1643  
1644 =over 4
1645  
1646 =item sub_hms example 1
1647  
1648 # given: synopsis;
1649  
1650 $date = $date->sub_hms(1, 0, 0);
1651  
1652 # $date->string; # 1988-01-31T23:00:00Z
1653  
1654 # $date->epoch; # 570668400
1655  
1656 =back
1657  
1658 =over 4
1659  
1660 =item sub_hms example 2
1661  
1662 # given: synopsis;
1663  
1664 $date = $date->sub_hms(undef, 1, 1);
1665  
1666 # $date->string; # 1988-01-31T23:58:59Z
1667  
1668 # $date->epoch; # 570671939
1669  
1670 =back
1671  
1672 =over 4
1673  
1674 =item sub_hms example 3
1675  
1676 # given: synopsis;
1677  
1678 $date = $date->sub_hms(1, 1);
1679  
1680 # $date->string; # 1988-01-31T22:59:00Z
1681  
1682 # $date->epoch; # 570668340
1683  
1684 =back
1685  
1686 =cut
1687  
1688 =head2 sub_hours
1689  
1690 sub_hours(Int $hours) (Any)
1691  
1692 The sub_hours method decrements the C<hour> attribute.
1693  
1694 I<Since C<0.01>>
1695  
1696 =over 4
1697  
1698 =item sub_hours example 1
1699  
1700 # given: synopsis;
1701  
1702 $date = $date->sub_hours(1);
1703  
1704 # $date->string; # 1988-01-31T23:00:00Z
1705  
1706 # $date->epoch; # 570668400
1707  
1708 =back
1709  
1710 =over 4
1711  
1712 =item sub_hours example 2
1713  
1714 # given: synopsis;
1715  
1716 $date = $date->sub_hours(25);
1717  
1718 # $date->string; # 1988-01-30T23:00:00Z
1719  
1720 # $date->epoch; # 570582000
1721  
1722 =back
1723  
1724 =over 4
1725  
1726 =item sub_hours example 3
1727  
1728 # given: synopsis;
1729  
1730 $date = $date->sub_hours(-1);
1731  
1732 # $date->string; # 1988-02-01T01:00:00Z
1733  
1734 # $date->epoch; # 570675600
1735  
1736 =back
1737  
1738 =cut
1739  
1740 =head2 sub_mdy
1741  
1742 sub_mdy(Maybe[Int] $months, Maybe[Int] $days, Maybe[Int] $years) (Date)
1743  
1744 The sub_mdy method decrements the C<month>, C<day>, and C<year> attributes.
1745  
1746 I<Since C<0.01>>
1747  
1748 =over 4
1749  
1750 =item sub_mdy example 1
1751  
1752 # given: synopsis;
1753  
1754 $date = $date->sub_mdy(1, 1, 1);
1755  
1756 # $date->string; # 1986-12-31T07:42:06Z
1757  
1758 # $date->epoch; # 536398926
1759  
1760 =back
1761  
1762 =over 4
1763  
1764 =item sub_mdy example 2
1765  
1766 # given: synopsis;
1767  
1768 $date = $date->sub_mdy(1, 1, undef);
1769  
1770 # $date->string; # 1987-12-31T13:30:56Z
1771  
1772 # $date->epoch; # 567955856
1773  
1774 =back
1775  
1776 =over 4
1777  
1778 =item sub_mdy example 3
1779  
1780 # given: synopsis;
1781  
1782 $date = $date->sub_mdy(1, 1);
1783  
1784 # $date->string; # 1987-12-31T13:30:56Z
1785  
1786 # $date->epoch; # 567955856
1787  
1788 =back
1789  
1790 =cut
1791  
1792 =head2 sub_minutes
1793  
1794 sub_minutes(Int $minutes) (Date)
1795  
1796 The sub_minutes method decrements the C<minute> attribute.
1797  
1798 I<Since C<0.01>>
1799  
1800 =over 4
1801  
1802 =item sub_minutes example 1
1803  
1804 # given: synopsis;
1805  
1806 $date = $date->sub_minutes(1);
1807  
1808 # $date->string; # 1988-01-31T23:59:00Z
1809  
1810 # $date->epoch; # 570671940
1811  
1812 =back
1813  
1814 =over 4
1815  
1816 =item sub_minutes example 2
1817  
1818 # given: synopsis;
1819  
1820 $date = $date->sub_minutes(61);
1821  
1822 # $date->string; # 1988-01-31T22:59:00Z
1823  
1824 # $date->epoch; # 570668340
1825  
1826 =back
1827  
1828 =over 4
1829  
1830 =item sub_minutes example 3
1831  
1832 # given: synopsis;
1833  
1834 $date = $date->sub_minutes(-1);
1835  
1836 # $date->string; # 1988-02-01T00:01:00Z
1837  
1838 # $date->epoch; # 570672060
1839  
1840 =back
1841  
1842 =cut
1843  
1844 =head2 sub_months
1845  
1846 sub_months(Int $months) (Date)
1847  
1848 The sub_months method decrements the C<month> attribute.
1849  
1850 I<Since C<0.01>>
1851  
1852 =over 4
1853  
1854 =item sub_months example 1
1855  
1856 # given: synopsis;
1857  
1858 $date = $date->sub_months(1);
1859  
1860 # $date->string; # 1988-01-01T13:30:56Z
1861  
1862 # $date->epoch; # 568042256
1863  
1864 =back
1865  
1866 =over 4
1867  
1868 =item sub_months example 2
1869  
1870 # given: synopsis;
1871  
1872 $date = $date->sub_months(13);
1873  
1874 # $date->string; # 1987-01-01T07:42:08Z
1875  
1876 # $date->epoch; # 536485328
1877  
1878 =back
1879  
1880 =over 4
1881  
1882 =item sub_months example 3
1883  
1884 # given: synopsis;
1885  
1886 $date = $date->sub_months(-1);
1887  
1888 # $date->string; # 1988-03-02T10:29:04Z
1889  
1890 # $date->epoch; # 573301744
1891  
1892 =back
1893  
1894 =cut
1895  
1896 =head2 sub_seconds
1897  
1898 sub_seconds(Int $seconds) (Date)
1899  
1900 The sub_seconds method decrements the C<second> attribute.
1901  
1902 I<Since C<0.01>>
1903  
1904 =over 4
1905  
1906 =item sub_seconds example 1
1907  
1908 # given: synopsis;
1909  
1910 $date = $date->sub_seconds(1);
1911  
1912 # $date->string; # 1988-01-31T23:59:59Z
1913  
1914 # $date->epoch; # 570671999
1915  
1916 =back
1917  
1918 =over 4
1919  
1920 =item sub_seconds example 2
1921  
1922 # given: synopsis;
1923  
1924 $date = $date->sub_seconds(61);
1925  
1926 # $date->string; # 1988-01-31T23:58:59Z
1927  
1928 # $date->epoch; # 570671939
1929  
1930 =back
1931  
1932 =over 4
1933  
1934 =item sub_seconds example 3
1935  
1936 # given: synopsis;
1937  
1938 $date = $date->sub_seconds(-1);
1939  
1940 # $date->string; # 1988-02-01T00:00:01Z
1941  
1942 # $date->epoch; # 570672001
1943  
1944 =back
1945  
1946 =cut
1947  
1948 =head2 sub_years
1949  
1950 sub_years(Int $years) (Date)
1951  
1952 The sub_years method decrements the C<years> attribute.
1953  
1954 I<Since C<0.01>>
1955  
1956 =over 4
1957  
1958 =item sub_years example 1
1959  
1960 # given: synopsis;
1961  
1962 $date = $date->sub_years(1);
1963  
1964 # $date->string; # 1987-01-31T18:11:10Z
1965  
1966 # $date->epoch; # 539115070
1967  
1968 =back
1969  
1970 =over 4
1971  
1972 =item sub_years example 2
1973  
1974 # given: synopsis;
1975  
1976 $date = $date->sub_years(25);
1977  
1978 # $date->string; # 1963-01-31T22:39:10Z
1979  
1980 # $date->epoch; # -218251250
1981  
1982 =back
1983  
1984 =over 4
1985  
1986 =item sub_years example 3
1987  
1988 # given: synopsis;
1989  
1990 $date = $date->sub_years(-1);
1991  
1992 # $date->string; # 1989-01-31T05:48:50Z
1993  
1994 # $date->epoch; # 602228930
1995  
1996 =back
1997  
1998 =cut
1999  
2000 =head2 truncate_to_day
2001  
2002 truncate_to_day() (Date)
2003  
2004 The truncate_to_day method truncates the date and time to the C<day>.
2005  
2006 I<Since C<0.09>>
2007  
2008 =over 4
2009  
2010 =item truncate_to_day example 1
2011  
2012 # given: synopsis;
2013  
2014 $date = $date->truncate_to_day;
2015  
2016 # $date->string; # 1988-02-01T00:00:00Z
2017  
2018 # $date->epoch; # 570672000
2019  
2020 =back
2021  
2022 =cut
2023  
2024 =head2 truncate_to_hour
2025  
2026 truncate_to_hour() (Date)
2027  
2028 The truncate_to_hour method truncates the date and time to the C<hour>.
2029  
2030 I<Since C<0.09>>
2031  
2032 =over 4
2033  
2034 =item truncate_to_hour example 1
2035  
2036 # given: synopsis;
2037  
2038 $date = $date->truncate_to_hour;
2039  
2040 # $date->string; # 1988-02-01T00:00:00Z
2041  
2042 # $date->epoch; # 570672000
2043  
2044 =back
2045  
2046 =cut
2047  
2048 =head2 truncate_to_minute
2049  
2050 truncate_to_minute() (Date)
2051  
2052 The truncate_to_minute method truncates the date and time to the C<minute>.
2053  
2054 I<Since C<0.09>>
2055  
2056 =over 4
2057  
2058 =item truncate_to_minute example 1
2059  
2060 # given: synopsis;
2061  
2062 $date = $date->truncate_to_minute(1);
2063  
2064 # $date->string; # 1988-02-01T00:00:00Z
2065  
2066 # $date->epoch; # 570672000
2067  
2068 =back
2069  
2070 =cut
2071  
2072 =head2 truncate_to_month
2073  
2074 truncate_to_month() (Date)
2075  
2076 The truncate_to_month method truncates the date and time to the C<month>.
2077  
2078 I<Since C<0.09>>
2079  
2080 =over 4
2081  
2082 =item truncate_to_month example 1
2083  
2084 # given: synopsis;
2085  
2086 $date = $date->truncate_to_month(1);
2087  
2088 # $date->string; # 1988-02-01T00:00:00Z
2089  
2090 # $date->epoch; # 570672000
2091  
2092 =back
2093  
2094 =cut
2095  
2096 =head2 truncate_to_quarter
2097  
2098 truncate_to_quarter() (Date)
2099  
2100 The truncate_to_quarter method truncates the date and time to the C<quarter>.
2101  
2102 I<Since C<0.09>>
2103  
2104 =over 4
2105  
2106 =item truncate_to_quarter example 1
2107  
2108 # given: synopsis;
2109  
2110 $date = $date->truncate_to_quarter(1);
2111  
2112 # $date->string; # 1988-01-01T00:00:00Z
2113  
2114 # $date->epoch; # 567993600
2115  
2116 =back
2117  
2118 =cut
2119  
2120 =head2 truncate_to_second
2121  
2122 truncate_to_second() (Date)
2123  
2124 The truncate_to_second method truncates the date and time to the C<second>.
2125  
2126 I<Since C<0.09>>
2127  
2128 =over 4
2129  
2130 =item truncate_to_second example 1
2131  
2132 # given: synopsis;
2133  
2134 $date = $date->truncate_to_second(1);
2135  
2136 # $date->string; # 1988-02-01T00:00:00Z
2137  
2138 # $date->epoch; # 570672000
2139  
2140 =back
2141  
2142 =cut
2143  
2144 =head2 truncate_to_year
2145  
2146 truncate_to_year() (Date)
2147  
2148 The truncate_to_year method truncates the date and time to the C<year>.
2149  
2150 I<Since C<0.09>>
2151  
2152 =over 4
2153  
2154 =item truncate_to_year example 1
2155  
2156 # given: synopsis;
2157  
2158 $date = $date->truncate_to_year(1);
2159  
2160 # $date->string; # 1988-01-01T00:00:00Z
2161  
2162 # $date->epoch; # 567993600
2163  
2164 =back
2165  
2166 =cut
2167  
2168 =head1 OPERATORS
2169  
2170 This package overloads the following operators:
2171  
2172 =cut
2173  
2174 =over 4
2175  
2176 =item operation: C<(!=)>
2177  
2178 This package overloads the C<!=> operator.
2179  
2180 B<example 1>
2181  
2182 # given: synopsis;
2183  
2184 my $result = $date != 570672001;
2185  
2186 # 1
2187  
2188 =back
2189  
2190 =over 4
2191  
2192 =item operation: C<(+)>
2193  
2194 This package overloads the C<+> operator.
2195  
2196 B<example 1>
2197  
2198 # given: synopsis;
2199  
2200 my $result = $date + 0;
2201  
2202 # 570672000
2203  
2204 =back
2205  
2206 =over 4
2207  
2208 =item operation: C<(-)>
2209  
2210 This package overloads the C<-> operator.
2211  
2212 B<example 1>
2213  
2214 # given: synopsis;
2215  
2216 my $result = $date - 0;
2217  
2218 # 570672000
2219  
2220 =back
2221  
2222 =over 4
2223  
2224 =item operation: C<(0+)>
2225  
2226 This package overloads the C<0+> operator.
2227  
2228 B<example 1>
2229  
2230 # given: synopsis;
2231  
2232 my $result = 0 + $date;
2233  
2234 # 570672000
2235  
2236 =back
2237  
2238 =over 4
2239  
2240 =item operation: C<(E<lt>)>
2241  
2242 This package overloads the C<E<lt>> operator.
2243  
2244 B<example 1>
2245  
2246 # given: synopsis;
2247  
2248 my $result = $date < 570672001;
2249  
2250 # 1
2251  
2252 =back
2253  
2254 =over 4
2255  
2256 =item operation: C<(E<lt>=)>
2257  
2258 This package overloads the C<E<lt>=> operator.
2259  
2260 B<example 1>
2261  
2262 # given: synopsis;
2263  
2264 my $result = $date <= 570672000;
2265  
2266 # 1
2267  
2268 =back
2269  
2270 =over 4
2271  
2272 =item operation: C<(==)>
2273  
2274 This package overloads the C<==> operator.
2275  
2276 B<example 1>
2277  
2278 # given: synopsis;
2279  
2280 my $result = $date == 570672000;
2281  
2282 # 1
2283  
2284 =back
2285  
2286 =over 4
2287  
2288 =item operation: C<(E<gt>)>
2289  
2290 This package overloads the C<E<gt>> operator.
2291  
2292 B<example 1>
2293  
2294 # given: synopsis;
2295  
2296 my $result = $date > 570671999;
2297  
2298 # 1
2299  
2300 =back
2301  
2302 =over 4
2303  
2304 =item operation: C<(E<gt>=)>
2305  
2306 This package overloads the C<E<gt>=> operator.
2307  
2308 B<example 1>
2309  
2310 # given: synopsis;
2311  
2312 my $result = $date >= 570672000;
2313  
2314 # 1
2315  
2316 =back
2317  
2318 =over 4
2319  
2320 =item operation: C<(eq)>
2321  
2322 This package overloads the C<eq> operator.
2323  
2324 B<example 1>
2325  
2326 # given: synopsis;
2327  
2328 my $result = $date eq '570672000';
2329  
2330 # 1
2331  
2332 =back
2333  
2334 =over 4
2335  
2336 =item operation: C<(ne)>
2337  
2338 This package overloads the C<ne> operator.
2339  
2340 B<example 1>
2341  
2342 # given: synopsis;
2343  
2344 my $result = $date ne '560672000';
2345  
2346 # 1
2347  
2348 =back
2349  
2350 =over 4
2351  
2352 =item operation: C<("")>
2353  
2354 This package overloads the C<""> operator.
2355  
2356 B<example 1>
2357  
2358 # given: synopsis;
2359  
2360 my $result = "$date";
2361  
2362 # "570672000"
2363  
2364 =back
2365  
2366 =over 4
2367  
2368 =item operation: C<(~~)>
2369  
2370 This package overloads the C<~~> operator.
2371  
2372 B<example 1>
2373  
2374 # given: synopsis;
2375  
2376 my $result = $date ~~ '570672000';
2377  
2378 # 1
2379  
2380 =back
« Venus/Replace.pm ↑ Summary Venus/Role/Proxyable.pm »