blib/lib/Venus/Date.pm

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