blib/lib/to_char.pl

filter: Statementstmt 29.5% 39 / 132 Branchbran 15.5% 9 / 58 Conditioncond 14.2% 1 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 29.1% 7 / 24 Podpod 4.1% 1 / 24 totaltotal 22.8% 57 / 249 CC 31 SCAR 34.2
CC
31
Cov
25%
fmt9
132.0
rr
12.0
to_char
6.4
CRAP 30.7
« blib/lib/OraSpriteFns.pl ↑ Summary blib/lib/to_date.pl »
1 1 my @timevals;
2
3 1 ▶return &to_char(@_) if (scalar(@_)); #ADDED 2003/12/15 TO MAKE INTO A GENERAL CALLABLE FUNCTION!
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 1 0 1
4
5 0 my ($s) = $_[0];
6 0 ▶my ($fmt) = $_[1] || 'dd-MON-rr';
Condition0%0/2
$_[1] || 'dd-MON-rr'
l!l
00
MC/DC0%0/1
$_[1] || 'dd-MON-rr'
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
7
8 0 $err = '';
9 0 $rtnTime = '';
10
11 0 @timevals = localtime($s);
12
13 0 foreach my $f (qw(month mon Month Mon MONTH MON))
14 {
15 0 $fmt =~ s/($f)/&{$f}($1)/eg;
16 0 ▶ last if ($err) ;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
17 }
18 0 foreach my $f (qw(ddd dd yyyy yy hh24 hh mi mm sssss ss rm rr))
19 {
20 0 $fmt =~ s/($f)/&{$f}($1)/egi;
21 0 ▶ last if ($err) ;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
22 }
23
24 #$fmt =~ s/\b(a)([\.m]?)\b/&a($1).$2/egi;
25 0 $fmt =~ s/\b([aApP])([\.[mM]?)\b/&{$1}.$2/eg;
26
27 0 $fmt =~ s/([0\$BSCL]*)([9D\.\,GV]+)(\s*CR|PR|EEEE)/&fmt9($1,$2,$3)/eg;
28
29 0 $rtnTime = $fmt;
30
31
32 sub fmt9
33 0 ▶{
Subroutine fmt9: not called CC=11 SCAR=48.8
Pod undocumented
34 0 my ($pre, $val, $suf) = (@_);
35 0 my $l = length($val) + 1;
36 0 my $dec;
37 0 ▶ $dec = length($1) if ($val =~ /[\.DV](\d+)/i);
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /[\.DV](\d+)/i 0 0 0
38 0 my $fmtstr = '%';
39 0 $fmtstr .= $l;
40 0 ▶ $fmtstr .= '.'.$dec if ($dec);
Branch: 1 branch
BranchTrueFalseTotal
if $dec 0 0 0
41 0 ▶ if ($suf =~ /(E)EEE/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($suf =~ /(E)EEE/i) { } 0 0 0
42 {
43 0 $fmtstr .= $1;
44 }
45 else
46 {
47 0 $fmtstr .= 'f';
48 }
49 0 my $t = sprintf($fmtstr, $s);
50 0 ▶ $t =~ s/\s(\S)/\$$1/ if ($pre =~ /[C\$]/i);
Branch: 1 branch
BranchTrueFalseTotal
if $pre =~ /[C\$]/i 0 0 0
51 0 ▶ $t =~ s/(\s)([^\s\-])/$1\+$2/ if ($pre =~ /S/i);
Branch: 1 branch
BranchTrueFalseTotal
if $pre =~ /S/i 0 0 0
52 0 ▶ $t =~ s/[0\.\,]/ /g if ($pre =~ /B/i && $t =~ /^[\s0\.\+\-\,]+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $pre =~ /B/i and $t =~ /^[\s0\.\+\-\,]+$/ 0 0 0
Condition0%0/3
$pre =~ /B/i and $t =~ /^[\s0\.\+\-\,]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$pre =~ /B/i and $t =~ /^[\s0\.\+\-\,]+$/
$pre =~ /B/i $t =~ /^[\s0\.\+\-\,]+$/
Truth table0%0/3
A and B
A= $pre =~ /B/iB= $t =~ /^[\s0\.\+\-\,]+$/
ABresult
0X0
100
111
53 0 ▶ $t =~ s/([\d\.\+\-]+)/
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /V/i 0 0 0
54 0 my ($one) = $1;
55 0 $one *= 10 ** $dec;
56 0 $one;
57 /e if ($val =~ /V/i);
58 0 ▶ if ($suf =~ /(\s*cr)/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($suf =~ /(\s*cr)/i) { } 0 0 0
elsif ($suf =~ /pr/i) { } 0 0 0
59 {
60 0 my ($one) = $1;
61 0 $t =~ s/\-(\S+)/$1$one/;
62 }
63 elsif ($suf =~ /pr/i)
64 {
65 0 $t =~ s/(\-)(\S+)(\s?)/\<$2\>/;
66 0 $t =~ s/\$\</\<\$/;
67 }
68 0 return $t;
69 }
70
71 sub month
72 0 ▶{
Subroutine month: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my @months = (
74 'january ', 'february ', 'march ', 'april ',
75 'may ', 'june ', 'july ', 'august ',
76 'september', 'october ', 'november ', 'december ');
77
78 0 return $months[$timevals[4]];
79 }
80
81 sub Month
82 0 ▶{
Subroutine Month: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my @months = (
84 'January ', 'February ', 'March ', 'April ',
85 'May ', 'June ', 'July ', 'August ',
86 'September', 'October ', 'November ', 'December ');
87
88 0 my $indx = shift;
89 0 return $months[$timevals[4]];
90 }
91
92 sub MONTH
93 0 ▶{
Subroutine MONTH: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my @months = (
95 'JANUARY ', 'FEBRUARY ', 'MARCH ', 'APRIL ',
96 'MAY ', 'JUNE ', 'JULY ', 'AUGUST ',
97 'SEPTEMBER', 'OCTOBER ', 'NOVEMBER ', 'DECEMBER ');
98
99 0 my $indx = shift;
100 0 return $months[$timevals[4]];
101 }
102
103 sub mon
104 0 ▶{
Subroutine mon: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my @months = ('jan', 'feb', 'mar', 'apr', 'may', 'jun',
106 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
107
108 0 my $indx = shift;
109 0 return $months[$timevals[4]];
110 }
111
112 sub Mon
113 1 ▶{
Subroutine Mon: called CC=1 SCAR=0.0
Pod undocumented
114 1 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
115 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
116
117 1 my $indx = shift;
118 1 return $months[$timevals[4]];
119 }
120
121 sub MON
122 0 ▶{
Subroutine MON: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my @months = ('JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
124 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC');
125
126 0 my $indx = shift;
127 0 return $months[$timevals[4]];
128 }
129
130 sub rm
131 0 ▶{
Subroutine rm: not called CC=1 SCAR=6.9
Pod undocumented
132 0 my @months = ('i', 'ii', 'iii', 'iv', 'v', 'vi',
133 'vii', 'viii', 'ix', 'x', 'xi', 'xii');
134
135 0 my $indx = shift;
136 0 return $months[$timevals[4]];
137 }
138
139 sub mm
140 1 ▶{
Subroutine mm: called CC=2 SCAR=7.1
Pod undocumented
141 1 my ($t) = $timevals[4] + 1;
142 1 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 1 1
143 1 return $t;
144 }
145
146 sub yyyy
147 1 ▶{
Subroutine yyyy: called CC=1 SCAR=0.0
Pod undocumented
148 1 return $timevals[5] + 1900;
149 }
150
151 sub yy
152 0 ▶{
Subroutine yy: not called CC=1 SCAR=6.9
Pod undocumented
153 0 return &rr;
154 }
155
156 sub rr
157 0 ▶{
Subroutine rr: not called CC=3 SCAR=24.8
Pod undocumented
158 0 my ($t) = $timevals[5];
159 0 ▶ $t -= 100 if ($t >= 100);
Branch: 1 branch
BranchTrueFalseTotal
if $t >= 100 0 0 0
160 0 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 0 0
161 0 return $t;
162 }
163
164 #sub ddd
165 #{
166 # return $mday;
167 #}
168
169 sub dd
170 1 ▶{
Subroutine dd: called CC=2 SCAR=7.1
Pod undocumented
171 1 my ($t) = $timevals[3];
172 1 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 1 1
173 1 return $t;
174 }
175
176 sub hh24
177 0 ▶{
Subroutine hh24: not called CC=2 SCAR=17.9
Pod undocumented
178 0 my ($t) = $timevals[2];
179 0 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 0 0
180 0 return $t;
181 }
182
183 sub hh
184 1 ▶{
Subroutine hh: called CC=4 SCAR=14.6
Pod undocumented
185 1 my ($t) = $timevals[2];
186 1 ▶ $t -= 12 if ($t >= 13);
Branch: 1 branch
BranchTrueFalseTotal
if $t >= 13 1 0 1
187 1 ▶ $t += 12 unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 1 1
188 1 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 1 0 1
189 1 return $t;
190 }
191
192 sub a
193 0 ▶{
Subroutine a: not called CC=2 SCAR=17.9
Pod documented
194 0 my ($t) = $timevals[2];
195 0 ▶ return 'a' if ($t < 12);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 12 0 0 0
196 0 return 'p';
197 }
198
199 sub p
200 0 ▶{
Subroutine p: not called CC=2 SCAR=17.9
Pod undocumented
201 0 my ($t) = $timevals[2];
202 0 ▶ return 'a' if ($t < 12);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 12 0 0 0
203 0 return 'p';
204 }
205
206 sub A
207 0 ▶{
Subroutine A: not called CC=2 SCAR=17.9
Pod undocumented
208 0 my ($t) = $timevals[2];
209 0 ▶ return 'A' if ($t < 12);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 12 0 0 0
210 0 return 'P';
211 }
212
213 sub P
214 0 ▶{
Subroutine P: not called CC=2 SCAR=17.9
Pod undocumented
215 0 my ($t) = $timevals[2];
216 0 ▶ return 'A' if ($t < 12);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 12 0 0 0
217 0 return 'P';
218 }
219
220 sub mi
221 0 ▶{
Subroutine mi: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my ($t) = $timevals[1];
223 0 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 0 0
224 0 return $t;
225 }
226
227 sub sssss
228 0 ▶{
Subroutine sssss: not called CC=1 SCAR=6.9
Pod undocumented
229 0 return (($timevals[2]*3600) + ($timevals[1]*60) + $timevals[0]);
230 }
231
232 sub ss
233 1 ▶{
Subroutine ss: called CC=2 SCAR=7.1
Pod undocumented
234 1 my ($t) = $timevals[0];
235 1 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 1 1
236 1 return $t;
237 }
238
239 sub ddd
240 0 ▶{
Subroutine ddd: not called CC=2 SCAR=17.9
Pod undocumented
241 0 my ($t) = $timevals[7] + 1;
242 0 ▶ $t = '0' . $t if ($t < 10);
Branch: 1 branch
BranchTrueFalseTotal
if $t < 10 0 0 0
243 0 return $t;
244 }
245
246 sub to_char
247 1 ▶{
Subroutine to_char: called CC=6 SCAR=18.5
Pod undocumented
248 1 my ($s) = $_[0];
249 1 ▶ my ($fmt) = $_[1] || 'dd-MON-rr';
Condition50%1/2
$_[1] || 'dd-MON-rr'
l!l
10
MC/DC0%0/1
$_[1] || 'dd-MON-rr'
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
250 #print "<BR>TO_CHAR($s|$fmt)=\n";
251 1 $err = '';
252 1 $rtnTime = '';
253
254 1 @timevals = localtime($s);
255 #print "<BR>timevals=".join('|',@timevals)."=\n";
256 1 foreach my $f (qw(month mon Month Mon MONTH MON))
257 {
258 6 $fmt =~ s/($f)/&{$f}($1)/eg;
259 6 ▶ last if ($err) ;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 6 6
260 }
261 1 foreach my $f (qw(ddd dd yyyy yy hh24 hh mi mm sssss ss rm rr))
262 {
263 12 $fmt =~ s/($f)/&{$f}($1)/egi;
264 12 ▶ last if ($err) ;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 12 12
265 }
266
267 #$fmt =~ s/\b(a)([\.m]?)\b/&a($1).$2/egi;
268 0 $fmt =~ s/\b([aApP])([\.[mM]?)\b/&{$1}.$2/eg;
269
270 0 $fmt =~ s/([0\$BSCL]*)([9D\.\,GV]+)(\s*CR|PR|EEEE)/&fmt9($1,$2,$3)/eg;
271
272 1 $rtnTime = $fmt;
273 #print "<BR>tochar returns =$rtnTime=\n";
274 1 return $rtnTime;
275 }
276
277 0 1
« blib/lib/OraSpriteFns.pl ↑ Summary blib/lib/to_date.pl »