Medley/DateTime.pm

filter: Statementstmt 84.1% 429 / 510 Branchbran 45.1% 129 / 286 Conditioncond 20.0% 6 / 30 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 100% 78 / 78 Podpod n/a totaltotal 69.6% 642 / 922 CC 160 SCAR 31.6
CC
160
Cov
68%
localDateTimeAdd
71.2
localDateTimeAdd
60.9
iso8601DateTime
22.0
CRAP 23.7
« Medley/Module/Overview.pm ↑ Summary Medley/Hostname.pm »
1 package Util::Medley::DateTime;
2 6 $Util::Medley::DateTime::VERSION = '0.047';
3 6 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Data::Printer alias => 'pdump';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Time::localtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Kavorka '-all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Time::ParseDate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use DateTime::Format::ISO8601::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use constant SECS_PER_MIN => 60;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use constant SECS_PER_HOUR => SECS_PER_MIN() * 60;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use constant SECS_PER_DAY => SECS_PER_HOUR() * 24;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 =head1 NAME
20  
21 Util::Medley::DateTime - Class with various datetime methods.
22  
23 =head1 VERSION
24  
25 version 0.047
26  
27 =cut
28  
29 =head1 SYNOPSIS
30  
31 my $dt = Util::Medley::DateTime->new;
32  
33 #
34 # positional
35 #
36 say $dt->localDateTime(time);
37  
38 #
39 # named pair
40 #
41 say $dt->localDateTime(epoch => time);
42
43 =cut
44  
45 ########################################################
46  
47 =head1 DESCRIPTION
48  
49 A small datetime library. This doesn't do any calculations itself, but
50 provides some simple methods to call for getting the date/time in commonly
51 used formats.
52  
53 =cut
54  
55 ########################################################
56  
57 =head1 ATTRIBUTES
58  
59 none
60  
61 =head1 METHODS
62  
63 =head2 iso8601DateTime
64  
65 Returns a iso8601-date-time string.
66  
67 =over
68  
69 =item usage:
70  
71 $dt->iso8601DateTime([$epoch]);
72  
73 $dt->iso8601DateTime([epoch => $epoch]);
74
75 =item args:
76  
77 =over
78  
79 =item epoch [Int]
80  
81 Epoch time used to generate iso8601-date-time string. Default is now.
82  
83 =back
84  
85 =back
86  
87 =cut
88  
89 6 ▶multi method iso8601DateTime (Num :$epoch = time) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine iso8601DateTime: called CC=15 SCAR=30.9
Branch: 10 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 2 2
if ($slice_length % 2 != 0) 0 2 2
if ($i <= $#_) 2 2 4
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 2 2
exists $_{'epoch'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch) or _failed_check(12, "Num", $epoch, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition11%1/9
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
200
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch)
!ll&&!rl&&r
000
defined $epoch and not ref $epoch
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
MC/DC0%0/3
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch)
defined $epoch not ref $epoch &Scalar::Util::looks_like_number($epoch)
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
Truth table0%0/4
A and not(B) and C
A= defined $epochB= not ref $epochC= &Scalar::Util::looks_like_number($epoch)
ABCresult
0XX0
10X0
1100
1111
90  
91 2 my $dt = DateTime->from_epoch(epoch => $epoch);
92 2 my $format = DateTime::Format::ISO8601::Format->new;
93 2 return $format->format_datetime($dt);
94 }
95  
96 6 ▶multi method iso8601DateTime (Num $epoch? = time) {
Subroutine BEGIN: called CC=1 SCAR=0.9
Subroutine BEGIN: called CC=1 SCAR=0.9
Subroutine iso8601DateTime: called CC=10 SCAR=29.1
Branch: 7 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if @_ > 1 0 2 2
$#_ >= 0 ? : 2 0 2
unless ($____nobble_checks) 0 2 2
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch) or _failed_check(12, "Num", $epoch, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch)
!ll&&!rl&&r
000
defined $epoch and not ref $epoch
!ll&&!rl&&r
000
MC/DC0%0/3
defined $epoch and not ref $epoch and &Scalar::Util::looks_like_number($epoch)
defined $epoch not ref $epoch &Scalar::Util::looks_like_number($epoch)
Truth table0%0/4
A and not(B) and C
A= defined $epochB= not ref $epochC= &Scalar::Util::looks_like_number($epoch)
ABCresult
0XX0
10X0
1100
1111
97  
98 2 return $self->iso8601DateTime(epoch => $epoch);
99 }
100  
101 =head2 iso8601DateTimeToEpoch
102  
103 Returns the epoch of a given iso8601-date-time string.
104  
105 =over
106  
107 =item usage:
108  
109 $dt->iso8601DateTimeToEpoch([$dateTime]);
110  
111 $dt->iso8601DateTime([dateTime => $dateTime]);
112
113 =item args:
114  
115 =over
116  
117 =item dateTime [Str]
118  
119 An iso8601-date-time string.
120  
121 =back
122  
123 =back
124  
125 =cut
126  
127 6 ▶multi method iso8601DateTimeToEpoch (Str :$dateTime!) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine iso8601DateTimeToEpoch: called CC=14 SCAR=29.3
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 1 1
if ($slice_length % 2 != 0) 0 1 1
if ($i <= $#_) 1 1 2
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 1 1
exists $_{'dateTime'} ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if (exists $_{"dateTime"}) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
128
129 1 my $dt = DateTime::Format::ISO8601->parse_datetime($dateTime);
130 1 return $dt->epoch;
131 }
132  
133 6 ▶multi method iso8601DateTimeToEpoch (Str $dateTime!) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine iso8601DateTimeToEpoch: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if @_ != 1 0 1 1
$#_ >= 0 ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
134  
135 1 return $self->iso8601DateTimeToEpoch(dateTime => $dateTime);
136 }
137  
138 =head2 localDateTime
139  
140 Returns the local-date-time in the format: YYYY-MM-DD HH:MM:SS.
141  
142 =over
143  
144 =item usage:
145  
146 $dt->localDateTime([time]);
147  
148 $dt->localDateTime([epoch => time]);
149
150 =item args:
151  
152 =over
153  
154 =item time [Int]
155  
156 Epoch time used to generate date/time string. Default is now.
157  
158 =back
159  
160 =back
161
162 =cut
163  
164 6 ▶multi method localDateTime (Int :$epoch = time) {
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine localDateTime: called CC=13 SCAR=27.4
Branch: 10 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 457 0 457
@_ ? : 457 0 457
unless ($____nobble_checks) 0 457 457
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 457 457
if ($slice_length % 2 != 0) 0 457 457
if ($i <= $#_) 2 457 459
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 2 2
exists $_{'epoch'} ? : 2 455 457
unless ($____nobble_checks) 0 457 457
Type::Tiny::XS::Int($epoch) or _failed_check(13, "Int", $epoch, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
45700
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
165
166 457 return $self->localDateTime($epoch);
167 }
168  
169 6 ▶multi method localDateTime (Int $epoch = time) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine localDateTime: called CC=8 SCAR=23.0
Branch: 7 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 458 0 458
@_ ? : 458 0 458
unless ($____nobble_checks) 0 458 458
if @_ > 1 0 458 458
$#_ >= 0 ? : 458 0 458
unless ($____nobble_checks) 0 458 458
Type::Tiny::XS::Int($epoch) or _failed_check(13, "Int", $epoch, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
170  
171 458 my $l = localtime($epoch);
172  
173 458 my $str = sprintf(
174 '%04d-%02d-%02d %02d:%02d:%02d',
175 $l->year + 1900,
176 $l->mon + 1,
177 $l->mday, $l->hour, $l->min, $l->sec
178 );
179  
180 458 return $str;
181 }
182  
183  
184 =head2 localDateTimeAdd
185  
186 Adds days, hours, mins, and/or secs to a local-date-time string.
187  
188 =over
189  
190 =item usage:
191  
192 $newDateTime = $dt->localDateTimeAdd($dateTime, [0, 1, 0, 0]);
193  
194 $newDateTime = $dt->localDateTimeAdd( dateTime => $dateTime,
195 [days => 0],
196 [hours => 1],
197 [mins => 0],
198 [secs => 0]);
199
200 =item args:
201  
202 =over
203  
204 =item dateTime [Str]
205  
206 A local-date-time string.
207  
208 =item days [Int]
209  
210 Days to add.
211  
212 =item hours [Int]
213  
214 Hours to add.
215  
216 =item mins [Int]
217  
218 Minutes to add.
219  
220 =item secs [Int]
221  
222 Seconds to add.
223  
224 =back
225  
226 =back
227
228 =cut
229  
230 multi method localDateTimeAdd (Str :$dateTime!,
231 Int :$days = 0,
232 Int :$hours = 0,
233 Int :$mins = 0,
234 6 ▶ Int :$secs = 0) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine localDateTimeAdd: called CC=30 SCAR=42.7
Branch: 23 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 2 2
if ($slice_length % 2 != 0) 0 2 2
if ($i <= $#_) 10 2 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 10 10
exists $_{'dateTime'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if (exists $_{"dateTime"}) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'days'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($days) or _failed_check(13, "Int", $days, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'hours'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($hours) or _failed_check(13, "Int", $hours, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'mins'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($mins) or _failed_check(13, "Int", $mins, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'secs'} ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($secs) or _failed_check(13, "Int", $secs, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
235  
236 2 my $epoch = $self->localDateTimeToEpoch(dateTime => $dateTime);
237  
238 2 ▶ $epoch+= $days * SECS_PER_DAY if $days;
Branch: 1 branch
BranchTrueFalseTotal
if $days 1 1 2
239 2 ▶ $epoch+= $hours * SECS_PER_HOUR if $hours;
Branch: 1 branch
BranchTrueFalseTotal
if $hours 2 0 2
240 2 ▶ $epoch+= $mins * SECS_PER_MIN if $mins;
Branch: 1 branch
BranchTrueFalseTotal
if $mins 1 1 2
241 2 ▶ $epoch+= $secs if $secs;
Branch: 1 branch
BranchTrueFalseTotal
if $secs 1 1 2
242
243 2 return $self->localDateTime(epoch => $epoch);
244 }
245  
246 multi method localDateTimeAdd (Str $dateTime,
247 Int $days = 0,
248 Int $hours = 0,
249 Int $mins = 0,
250 6 ▶ Int $secs = 0) {
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine localDateTimeAdd: called CC=22 SCAR=41.1
Branch: 21 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if @_ < 1 0 2 2
if @_ > 5 0 2 2
$#_ >= 0 ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($days) or _failed_check(13, "Int", $days, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 2 0 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($hours) or _failed_check(13, "Int", $hours, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 3 ? : 1 1 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($mins) or _failed_check(13, "Int", $mins, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 4 ? : 1 1 2
unless ($____nobble_checks) 0 2 2
Type::Tiny::XS::Int($secs) or _failed_check(13, "Int", $secs, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
251  
252 2 return $self->localDateTimeAdd(dateTime => $dateTime,
253 days => $days,
254 hours => $hours,
255 mins => $mins,
256 secs => $secs);
257 }
258  
259  
260 =head2 localDateTimeToEpoch
261  
262 Converts a local-date-time string to epoch.
263  
264 =over
265  
266 =item usage:
267  
268 $epoch = $dt->localDateTimeToEpoch($dateTime);
269  
270 $epoch = $dt->localDateTimeToEpoch(dateTime => $dateTime);
271
272 =item args:
273  
274 =over
275  
276 =item dateTime [Str]
277  
278 The local-date-time string to convert.
279  
280 =back
281  
282 =back
283
284 =cut
285  
286 6 ▶multi method localDateTimeToEpoch (Str :$dateTime!) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine localDateTimeToEpoch: called CC=15 SCAR=30.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 6 0 6
@_ ? : 6 0 6
unless ($____nobble_checks) 0 6 6
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 6 6
if ($slice_length % 2 != 0) 0 6 6
if ($i <= $#_) 6 6 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 6 6
exists $_{'dateTime'} ? : 6 0 6
unless ($____nobble_checks) 0 6 6
if (exists $_{"dateTime"}) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
600
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
287  
288 6 ▶ if (!$self->localDateTimeIsValid(dateTime => $dateTime)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->localDateTimeIsValid("dateTime", $dateTime)) 0 6 6
289 0 confess "invalid date-time format: $dateTime";
290 }
291  
292 6 my ($date, $time) = split(/\s+/, $dateTime);
293 6 my ($year, $mon, $mday) = split(/-/, $date);
294 6 my ($hour, $min, $sec) = split(/\:/, $time);
295
296 6 my $epoch = timelocal( $sec, $min, $hour, $mday, $mon - 1, $year );
297
298 6 return $epoch;
299 }
300  
301 6 ▶multi method localDateTimeToEpoch (Str $dateTime) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine localDateTimeToEpoch: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if @_ != 1 0 1 1
$#_ >= 0 ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
302
303 1 return $self->localDateTimeToEpoch(dateTime => $dateTime);
304 }
305  
306 =head2 localDateTimeIsValid
307  
308 Validates the date-time string against: YYYY-MM-DD HH:MM:SS. Also,
309 checks if it is actually a valid date-time.
310  
311 =over
312  
313 =item usage:
314  
315 $dt->localDateTimeIsValid($dateTime);
316  
317 $dt->localDateTime(dateTime => $dateTime);
318
319 =item args:
320  
321 =over
322  
323 =item dateTime [Str]
324  
325 The date-time string to validate.
326  
327 =back
328  
329 =back
330
331 =cut
332  
333 6 ▶multi method localDateTimeIsValid (Str :$dateTime!) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine localDateTimeIsValid: called CC=16 SCAR=30.3
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 10 0 10
@_ ? : 10 0 10
unless ($____nobble_checks) 0 10 10
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 10 10
if ($slice_length % 2 != 0) 0 10 10
if ($i <= $#_) 10 10 20
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 10 10
exists $_{'dateTime'} ? : 10 0 10
unless ($____nobble_checks) 0 10 10
if (exists $_{"dateTime"}) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
334
335 10 ▶ if ($dateTime =~ /^\d\d\d\d-\d\d\-\d\d \d\d\:\d\d\:\d\d$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dateTime =~ /^\d\d\d\d-\d\d\-\d\d \d\d\:\d\d\:\d\d$/u) 9 1 10
336
337 9 my $epoch = parsedate($dateTime, VALIDATE=>1);
338 9 ▶ if ($epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($epoch) 8 1 9
339 8 return 1;
340 }
341 }
342
343 2 return 0;
344 }
345  
346 6 ▶multi method localDateTimeIsValid (Str $dateTime) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine localDateTimeIsValid: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 4 0 4
@_ ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if @_ != 1 0 4 4
$#_ >= 0 ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($dateTime) or _failed_check(9, "Str", $dateTime, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
347  
348 4 return $self->localDateTimeIsValid(dateTime => $dateTime);
349 }
350  
351  
352 =head2 timeMs
353  
354 Returns the current epoch in milliseconds.
355  
356 =over
357  
358 =item usage:
359  
360 $ms = $dt->timeMs;
361
362 =back
363
364 =cut
365  
366 6 ▶method timeMs {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine timeMs: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
367
368 1 return int(Time::HiRes::gettimeofday() * 1000);
369 }
370  
371 6 1;
« Medley/Module/Overview.pm ↑ Summary Medley/Hostname.pm »