lib/DR/DateTime.pm

filter: Statementstmt 91.3% 223 / 244 Branchbran 77.3% 65 / 84 Conditioncond 66.6% 24 / 36 MC/DCmcdc 20.0% 4 / 20 Subroutinesub 88.0% 44 / 50 Podpod 76.9% 20 / 26 totaltotal 82.6% 380 / 460 SCAR 45.6
CC
78
Cov
86%
add
18.6
parse
17.6
new
9.3
CRAP 95.7
« blib/lib/DR/DateTime.pm ↑ Summary blib/lib/DR/DateTime/Defaults.pm »
1 package DR::DateTime;
2 7 ▶use DR::DateTime::Defaults;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 7 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 our $VERSION = '0.08';
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Time::Zone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 use overload
16 9 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 8 ▶ '""' => sub { shift->strftime('%F %T%z') },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 '<=>' => sub {
19 2 ▶ my ($self, $cv, $flip) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
20 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
21 1 return $self->fepoch <=> $cv->fepoch;
22 }
23 1 return $self->fepoch <=> $cv;
24 },
25  
26 'cmp' => sub {
27 2 ▶ my ($self, $cv, $flip) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
28 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
29 1 return $self->strftime('%F %T%z') cmp $cv->strftime('%F %T%z');
30 }
31 1 my $pct = $self->parse($cv);
32 1 ▶ return $self->strftime('%F %T%z') cmp $cv unless $pct;
Branch: 1 branch
BranchTrueFalseTotal
unless $pct 0 1 1
33 1 return $self->strftime('%F %T%z') cmp $pct->strftime('%F %T%z');
34 },
35  
36 2 ▶ int => sub { shift->epoch },
Subroutine __ANON__: called CC=1 SCAR=0.0
37  
38 '+' => sub {
39 2 ▶ my ($self, $cv, $flip) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.6
40 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 0 2 2
41 0 return $self->new(
42 $self->fepoch + $cv->fepoch,
43 $self->[1]
44 )
45 }
46  
47 $self->new(
48 2 $self->fepoch + $cv,
49 $self->[1]
50 )
51 },
52  
53 '-' => sub {
54 4 ▶ my ($self, $cv, $flip) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.0
55 4 warn "$self $cv $flip";
56  
57 4 ▶ if ($flip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flip) { } 2 2 4
58 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 0 2 2
59 0 return $cv->fepoch - $self->fepoch;
60 }
61 2 return $cv - $self->fepoch;
62 } else {
63 2 ▶ if ('DR::DateTime' eq ref $cv) { # date1 - $date2
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
64 1 return $self->fepoch - $cv->fepoch;
65 }
66 1 return $self->new($self->fepoch - $cv, $self->[1]);
67 }
68 }
69 7 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71  
72 sub new {
73 48 ▶ my ($class, $stamp, $tz) = @_;
Subroutine new: called CC=9 SCAR=22.3
Pod documented
74 48 ▶ $stamp //= time;
Condition66%2/3
$stamp //= time
l!l&&r!l&&!r
4440
MC/DC0%0/2
$stamp //= time
$stamp time
Truth table66%2/3
A //= B
A= $stampB= time
ABresult
1X1
011
000
75  
76 48 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 39 9 48
77 39 $tz =~ /^([+-])?(\d{2})(\d{2})?$/;
78 39 ▶ croak "Wrong timezone format" unless defined $2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $2 0 39 39
79  
80 39 ▶ $tz = join '',
Condition100%4/4
$1 // "+"
l!l
354
$3 // "00"
l!l
363
MC/DC100%1/1
$1 // "+"
$1
MC/DC100%1/1
$3 // "00"
$3
Truth table100%2/2
A
A= $1
Aresult
11
00
Truth table100%2/2
A
A= $3
Aresult
11
00
81 $1 // '+',
82 $2,
83 $3 // '00';
84 }
85  
86 48 ▶ $tz = $DR::DateTime::Defaults::TZFORCE
Branch: 1 branch
BranchTrueFalseTotal
if defined $DR::DateTime::Defaults::TZFORCE 2 46 48
87 if defined $DR::DateTime::Defaults::TZFORCE;
88  
89 48 ▶ bless [ $stamp, $tz // () ] => ref($class) || $class;
Condition66%4/6
$tz // ()
l!l&&r!l&&!r
4170
ref $class || $class
l!l&&r!l&&!r
18300
MC/DC0%0/2
$tz // ()
$tz ()
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A // B
A= $tzB= ()
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
90 }
91  
92 sub parse {
93 35 ▶ my ($class, $str, $default_tz, $nocheck) = @_;
Subroutine parse: called CC=17 SCAR=28.7
Pod documented
94 35 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 35 35
95 35 my ($y, $m, $d, $H, $M, $S, $ns, $z);
96  
97 35 for ($str) {
98  
99 35 ▶ if (/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\d+$/) 1 34 35
100 1 ▶ return $class->new($str, $default_tz // '+0000');
Condition50%1/2
$default_tz // "+0000"
l!l
01
MC/DC0%0/1
$default_tz // "+0000"
$default_tz
Truth table50%1/2
A
A= $default_tz
Aresult
11
00
101 }
102 34 ▶ if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) 28 6 34
103 28 ($y, $m, $d, $H, $M, $S, $ns, $z) =
104 ($1, $2, $3, $4, $5, $6, $7, $8);
105 28 goto PARSED;
106 }
107
108 6 ▶ if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2})$/) 2 4 6
109 2 ($y, $m, $d, $H, $M, $S, $ns, $z) =
110 ($1, $2, $3, $4, $5, 0, 0, undef);
111 2 goto PARSED;
112 }
113
114 4 ▶ if (/^(\d{4})-(\d{2})-(\d{2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})$/) 1 3 4
115 1 ($y, $m, $d, $H, $M, $S, $ns, $z) =
116 ($1, $2, $3, 0, 0, 0, 0, undef);
117 1 goto PARSED;
118 }
119  
120 3 ▶ if (/^(\d{1,2})\.(\d{1,2})\.(\d{4})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{1,2})\.(\d{1,2})\.(\d{4})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) 3 0 3
121 3 ($y, $m, $d, $H, $M, $S, $ns, $z) =
122 ($3, $2, $1, $4, $5, $6, $7, $8);
123 3 goto PARSED;
124 }
125  
126 0 return undef;
127 }
128  
129  
130 PARSED:
131  
132 34 ▶ $z //= $default_tz // '+0000';
Condition60%3/5
$z //= $default_tz // "+0000"
l!l&&r!l&&!r
2950
$default_tz // "+0000"
l!l
05
MC/DC0%0/2
$z //= $default_tz // "+0000"
$z $default_tz
Truth table33%1/3
A //= B
A= $zB= $default_tz
ABresult
1X1
011
000
133 34 for ($z) {
134 34 ▶ if (/^[+-]\d{1,4}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[+-]\d{1,4}$/) { } 34 0 34
135 34 s/^([+-])(\d|\d{3})$/${1}0$2/;
136 34 s/^([+-])(\d{2})$/${1}${2}00/;
137 } else {
138 0 croak "Wrong time zone format: '$z'";
139 }
140 }
141 34 for ($m) {
142 34 s/^0//;
143 34 $_--;
144 }
145 34 for ($d, $H, $M, $S) {
146 136 s/^0//;
147 }
148 34 $y -= 1900;
149  
150 34 ▶ $ns //= 0;
Condition100%2/2
$ns //= 0
l!l
1816
MC/DC100%1/1
$ns //= 0
$ns
Truth table100%2/2
A
A= $ns
Aresult
11
00
151 34 my $stamp = eval {
152 34 ▶ local $SIG{__DIE__} = sub {}; # Ick!
Subroutine __ANON__: not called CC=1 SCAR=0.0
153 34 ▶ return Time::Local::timegm_nocheck($S,$M,$H,$d,$m,$y) if $nocheck;
Branch: 1 branch
BranchTrueFalseTotal
if $nocheck 9 25 34
154 25 Time::Local::timegm($S,$M,$H,$d,$m,$y);
155 };
156 34 $stamp += $ns;
157  
158 34 my $offset = Time::Zone::tz_offset($z, $stamp);
159 34 $class->new($stamp - $offset, $z);
160 }
161  
162 149 ▶sub fepoch { shift->[0] }
Subroutine fepoch: called CC=1 SCAR=0.0
Pod documented
163 300 ▶sub epoch { POSIX::floor(shift->[0]) }
Subroutine epoch: called CC=1 SCAR=0.0
Pod documented
164 211 ▶sub tz { shift->[1] // $DR::DateTime::Defaults::TZ }
Subroutine tz: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
+(shift())->[1] // $DR::DateTime::Defaults::TZ
l!l&&r!l&&!r
181300
MC/DC0%0/2
+(shift())->[1] // $DR::DateTime::Defaults::TZ
+(shift())->[1] $DR::DateTime::Defaults::TZ
Truth table66%2/3
A // B
A= +(shift())->[1]B= $DR::DateTime::Defaults::TZ
ABresult
1X1
011
000
165  
166 sub strftime :method {
167 128 ▶ my ($self, $format) = @_;
Subroutine strftime: called CC=5 SCAR=16.3
Pod documented
168 128 ▶ croak 'Invalid format' unless $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 0 128 128
169 128 my $offset = Time::Zone::tz_offset($self->tz, $self->epoch);
170 128 my $stamp = $self->epoch + $offset;
171 128 my $fstamp = $self->fepoch + $offset;
172  
173 128 state $patterns;
174 128 ▶ unless ($patterns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($patterns) 7 121 128
175 $patterns = {
176 0 ▶ '%' => sub { '%' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
177 52 ▶ 'z' => sub { shift->tz },
Subroutine __ANON__: called CC=1 SCAR=0.0
178 0 ▶ 'Z' => sub { shift->tz },
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 'N' => sub {
180 20 ▶ int(1_000_000_000 * abs($_[2] - $_[1])) }
Subroutine __ANON__: called CC=1 SCAR=0.0
181  
182 7 };
183 7 for my $sp (split //, 'aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyY') {
184 182 ▶ $patterns->{$sp} = sub { POSIX::strftime "%$sp", gmtime $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
185 280 }
186 }
187  
188 128 $format =~ s{%([a-zA-Z%])}
189 254 ▶ { $patterns->{$1} ? $patterns->{$1}->($self, $stamp, $fstamp) : "%$1" }sgex;
Branch: 1 branch
BranchTrueFalseTotal
$patterns->{$1} ? : 254 0 254
190  
191 128 $format;
192 }
193  
194  
195 7 ▶sub year { shift->strftime('%Y') }
Subroutine year: called CC=1 SCAR=0.0
Pod documented
196  
197 sub month {
198 9 ▶ for my $m (shift->strftime('%m')) {
Subroutine month: called CC=2 SCAR=6.9
Pod documented
199 9 $m =~ s/^0//;
200 9 return $m;
201 }
202 }
203  
204 sub day {
205 28 ▶ for my $d (shift->strftime('%d')) {
Subroutine day: called CC=2 SCAR=6.9
Pod documented
206 28 $d =~ s/^0//;
207 28 return $d;
208 }
209 }
210  
211 2 ▶sub day_of_week { shift->strftime('%u') }
Subroutine day_of_week: called CC=1 SCAR=0.0
Pod documented
212  
213 2 ▶sub quarter { POSIX::ceil(shift->month / 3) }
Subroutine quarter: called CC=1 SCAR=0.0
Pod undocumented
214  
215 sub hour {
216 11 ▶ for my $h (shift->strftime('%H')) {
Subroutine hour: called CC=2 SCAR=6.9
Pod documented
217 11 $h =~ s/^0//;
218 11 return $h;
219 }
220 }
221  
222 sub minute {
223 6 ▶ for my $m (shift->strftime('%M')) {
Subroutine minute: called CC=2 SCAR=6.9
Pod documented
224 6 $m =~ s/^0//;
225 6 return $m;
226 }
227 }
228 sub second {
229 4 ▶ for my $s (shift->strftime('%S')) {
Subroutine second: called CC=2 SCAR=6.9
Pod documented
230 4 $s =~ s/^0//;
231 4 return $s;
232 }
233 }
234  
235 4 ▶sub nanosecond { shift->strftime('%N') }
Subroutine nanosecond: called CC=1 SCAR=0.0
Pod documented
236  
237 sub hms {
238 2 ▶ my ($self, $sep) = @_;
Subroutine hms: called CC=3 SCAR=11.1
Pod undocumented
239 2 ▶ $sep //= ':';
Condition50%1/2
$sep //= ":"
l!l
20
MC/DC0%0/1
$sep //= ":"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
240 2 for ($sep) {
241 2 s/%/%%/g;
242 }
243 2 $self->strftime("%H$sep%M$sep%S");
244 }
245  
246 sub datetime {
247 0 ▶ my ($self) = @_;
Subroutine datetime: not called CC=1 SCAR=6.9
Pod undocumented
248 0 return join 'T', $self->ymd, $self->hms;
249 }
250  
251 sub ymd {
252 2 ▶ my ($self, $sep) = @_;
Subroutine ymd: called CC=3 SCAR=11.1
Pod undocumented
253 2 ▶ $sep //= ':';
Condition50%1/2
$sep //= ":"
l!l
20
MC/DC0%0/1
$sep //= ":"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
254 2 for ($sep) {
255 2 s/%/%%/g;
256 }
257 2 $self->strftime("%Y$sep%m$sep%d");
258 }
259  
260 2 ▶sub time_zone { goto \&tz }
Subroutine time_zone: called CC=1 SCAR=0.0
Pod documented
261 0 ▶sub hires_epoch { goto \&fepoch }
Subroutine hires_epoch: not called CC=1 SCAR=6.9
Pod documented
262 sub _fix_date_after_arith_month {
263 9 ▶ my ($self, $new) = @_;
Subroutine _fix_date_after_arith_month: called CC=3 SCAR=11.0
264 9 ▶ return $new->fepoch if $self->day == $new->day;
Branch: 1 branch
BranchTrueFalseTotal
if $self->day == $new->day 7 2 9
265 2 ▶ if ($new->day < $self->day) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new->day < $self->day) 2 0 2
266 2 $new->[0] -= 86400;
267 }
268 2 $new->fepoch;
269 }
270 sub add {
271 6 ▶ my ($self, %set) = @_;
Subroutine add: called CC=18 SCAR=29.2
Pod documented
272
273 6 for my $n (delete $set{nanosecond}) {
274 6 ▶ last unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 6 0 6
275 0 $self->[0] += $n / 1_000_000_000;
276 }
277  
278 6 for my $s (delete $set{second}) {
279 6 ▶ last unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 5 1 6
280 1 $self->[0] += $s;
281 }
282  
283 6 for my $m (delete $set{minute}) {
284 6 ▶ last unless defined $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 6 0 6
285 0 $self->[0] += $m * 60;
286 }
287
288 6 for my $h (delete $set{hour}) {
289 6 ▶ last unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 5 1 6
290 1 $self->[0] += $h * 3600;
291 }
292  
293 6 for my $d (delete $set{day}) {
294 6 ▶ last unless defined $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 5 1 6
295 1 $self->[0] += $d * 86400;
296 }
297  
298 6 for my $m (delete $set{month}) {
299 6 ▶ last unless defined $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 2 4 6
300 4 my $nm = $self->month + $m;
301  
302 4 ▶ $set{year} //= 0;
Condition100%2/2
$set{"year"} //= 0
l!l
13
MC/DC100%1/1
$set{"year"} //= 0
$set{"year"}
Truth table100%2/2
A
A= $set{"year"}
Aresult
11
00
303 4 ▶ while ($nm > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm > 12) 1 4 5
304 1 $nm -= 12;
305 1 $set{year}++;
306 }
307  
308 4 ▶ while ($nm < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm < 1) 0 4 4
309 0 $nm += 12;
310 0 $set{year}--;
311 }
312 4 my $str = $self->strftime('%F %T.%N %z');
313 4 $str =~ s/(\d{4})-\d{2}-/sprintf "%s-%02d-", $1, $nm/e;
314 4 $self->[0] =
315 $self->_fix_date_after_arith_month($self->parse($str, undef, 1));
316 }
317  
318 6 for my $y (delete $set{year}) {
319 6 ▶ last unless defined $y;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 1 5 6
320 5 $y += $self->year;
321 5 my $str = $self->strftime('%F %T.%N %z');
322 5 $str =~ s/^\d{4}/$y/;
323 5 $self->[0] =
324 $self->_fix_date_after_arith_month($self->parse($str, undef, 1));
325 }
326 6 $self;
327 }
328  
329 sub subtract {
330 0 ▶ my ($self, %set) = @_;
Subroutine subtract: not called CC=2 SCAR=17.9
Pod undocumented
331  
332 0 my %sub;
333 0 ▶ while (my ($k, $v) = each %set) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %set) 0 0 0
334 0 $sub{$k} = -$v;
335 }
336 0 $self->add(%sub);
337 }
338  
339 sub truncate {
340 6 ▶ my ($self, %opts) = @_;
Subroutine truncate: called CC=8 SCAR=20.8
Pod documented
341  
342 6 ▶ my $to = $opts{to} // 'second';
Condition50%1/2
$opts{"to"} // "second"
l!l
60
MC/DC0%0/1
$opts{"to"} // "second"
$opts{"to"}
Truth table50%1/2
A
A= $opts{"to"}
Aresult
11
00
343  
344 6 ▶ if ($to eq 'second') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "second") 1 5 6
345 1 $self->[0] = $self->epoch;
346 1 return $self;
347 }
348  
349 5 my $str;
350 5 ▶ if ($to eq 'minute') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "minute") 1 4 5
351 1 $str = $self->strftime('%F %H:%M:00%z');
352 1 goto PARSE;
353 }
354  
355 4 ▶ if ($to eq 'hour') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "hour") 1 3 4
356 1 $str = $self->strftime('%F %H:00:00%z');
357 1 goto PARSE;
358 }
359
360 3 ▶ if ($to eq 'day') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "day") 1 2 3
361 1 $str = $self->strftime('%F 00:00:00%z');
362 1 goto PARSE;
363 }
364  
365 2 ▶ if ($to eq 'month') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "month") 1 1 2
366 1 $str = $self->strftime('%Y-%m-01 00:00:00%z');
367 1 goto PARSE;
368 }
369
370 1 ▶ if ($to eq 'year') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "year") 1 0 1
371 1 $str = $self->strftime('%Y-01-01 00:00:00%z');
372 1 goto PARSE;
373 }
374  
375 0 croak "Can not truncate the datetime to '$to'";
376  
377 5 PARSE:
378 $self->[0] = $self->parse($str)->epoch;
379 5 $self;
380 }
381  
382 sub clone {
383 1 ▶ my ($self) = @_;
Subroutine clone: called CC=2 SCAR=8.1
Pod documented
384 1 ▶ bless [ @$self ] => ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
385 }
386  
387 sub set_time_zone {
388 1 ▶ my ($self, $tz) = @_;
Subroutine set_time_zone: called CC=5 SCAR=17.1
Pod documented
389 1 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 1 0 1
390 1 for ($tz) {
391 1 s/^\d{1,4}$/+$&/;
392 1 s/^([+-])(\d)$/${1}0${2}00/;
393 1 s/^([+-]\d{2})$/${1}00/;
394 1 s/^([+-])(\d{3})$/${1}0$2/;
395 }
396  
397 1 ▶ if ($tz eq 'local') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tz eq 'local') { } 0 1 1
elsif (not $tz =~ /^[+-]\d{4}$/) { } 0 1 1
398 0 $tz = undef;
399 } elsif ($tz !~ /^[+-]\d{4}$/) {
400 0 croak "Wrong time zone: '$tz'";
401 }
402 }
403 1 $self->[1] = $tz;
404 1 $self;
405 }
406  
407 1 ▶sub set_tz { goto \&set_time_zone }
Subroutine set_tz: called CC=1 SCAR=0.0
Pod undocumented
408  
409 7 1;
410  
411 __END__
« blib/lib/DR/DateTime.pm ↑ Summary blib/lib/DR/DateTime/Defaults.pm »