Sisimai/DateTime.pm

filter: Statementstmt 99.1% 111 / 112 Branchbran 90.0% 72 / 80 Conditioncond 70.7% 46 / 65 MC/DCmcdc 50.0% 19 / 38 Subroutinesub 100% 12 / 12 Podpod 40.0% 2 / 5 totaltotal 83.9% 262 / 312 CC 67 SCAR 37.9
CC
67
Cov
89%
parse
62.5
second2tz
6.0
tz2second
6.0
CRAP 44.5
« Sisimai/Lhost/Courier.pm ↑ Summary Sisimai/Lhost/V5sendmail.pm »
1 package Sisimai::DateTime;
2 87 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 87 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 87 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub TZ_OFFSET() { 54000 } # Max time zone offset, 54000 seconds
8 87 ▶use constant MonthName => {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 'full' => [qw|January February March April May June July August September October November December|],
10 'abbr' => [qw|Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec|],
11 87 };
12 87 ▶use constant DayOfWeek => {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 'full' => [qw|Sunday Monday Tuesday Wednesday Thursday Friday Saturday|],
14 'abbr' => [qw|Sun Mon Tue Wed Thu Fri Sat|],
15 87 };
16 87 ▶use constant TimeZones => {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 # http://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
18 #'ACDT' => '+1030', # Australian Central Daylight Time UTC+10:30
19 #'ACST' => '+0930', # Australian Central Standard Time UTC+09:30
20 #'ACT' => '+0800', # ASEAN Common Time UTC+08:00
21 'ADT' => '-0300', # Atlantic Daylight Time UTC-03:00
22 #'AEDT' => '+1100', # Australian Eastern Daylight Time UTC+11:00
23 #'AEST' => '+1000', # Australian Eastern Standard Time UTC+10:00
24 #'AFT' => '+0430', # Afghanistan Time UTC+04:30
25 'AKDT' => '-0800', # Alaska Daylight Time UTC-08:00
26 'AKST' => '-0900', # Alaska Standard Time UTC-09:00
27 #'AMST' => '+0500', # Armenia Summer Time UTC+05:00
28 #'AMT' => '+0400', # Armenia Time UTC+04:00
29 #'ART' => '-0300', # Argentina Time UTC+03:00
30 #'AST' => '+0300', # Arab Standard Time (Kuwait, Riyadh) UTC+03:00
31 #'AST' => '+0400', # Arabian Standard Time (Abu Dhabi, Muscat) UTC+04:00
32 #'AST' => '+0300', # Arabic Standard Time (Baghdad) UTC+03:00
33 'AST' => '-0400', # Atlantic Standard Time UTC-04:00
34 #'AWDT' => '+0900', # Australian Western Daylight Time UTC+09:00
35 #'AWST' => '+0800', # Australian Western Standard Time UTC+08:00
36 #'AZOST'=> '-0100', # Azores Standard Time UTC-01:00
37 #'AZT' => '+0400', # Azerbaijan Time UTC+04:00
38 #'BDT' => '+0800', # Brunei Time UTC+08:00
39 #'BIOT' => '+0600', # British Indian Ocean Time UTC+06:00
40 #'BIT' => '-1200', # Baker Island Time UTC-12:00
41 #'BOT' => '-0400', # Bolivia Time UTC-04:00
42 #'BRT' => '-0300', # Brasilia Time UTC-03:00
43 #'BST' => '+0600', # Bangladesh Standard Time UTC+06:00
44 #'BST' => '+0100', # British Summer Time (British Standard Time from Feb 1968 to Oct 1971) UTC+01:00
45 #'BTT' => '+0600', # Bhutan Time UTC+06:00
46 #'CAT' => '+0200', # Central Africa Time UTC+02:00
47 #'CCT' => '+0630', # Cocos Islands Time UTC+06:30
48 'CDT' => '-0500', # Central Daylight Time (North America) UTC-05:00
49 #'CEDT' => '+0200', # Central European Daylight Time UTC+02:00
50 #'CEST' => '+0200', # Central European Summer Time UTC+02:00
51 #'CET' => '+0100', # Central European Time UTC+01:00
52 #'CHAST'=> '+1245', # Chatham Standard Time UTC+12:45
53 #'CIST' => '-0800', # Clipperton Island Standard Time UTC-08:00
54 #'CKT' => '-1000', # Cook Island Time UTC-10:00
55 #'CLST' => '-0300', # Chile Summer Time UTC-03:00
56 #'CLT' => '-0400', # Chile Standard Time UTC-04:00
57 #'COST' => '-0400', # Colombia Summer Time UTC-04:00
58 #'COT' => '-0500', # Colombia Time UTC-05:00
59 'CST' => '-0600', # Central Standard Time (North America) UTC-06:00
60 #'CST' => '+0800', # China Standard Time UTC+08:00
61 #'CVT' => '-0100', # Cape Verde Time UTC-01:00
62 #'CXT' => '+0700', # Christmas Island Time UTC+07:00
63 #'ChST' => '+1000', # Chamorro Standard Time UTC+10:00
64 # 'DST' => '' # Daylight saving time Depending
65 #'DFT' => '+0100', # AIX specific equivalent of Central European Time UTC+01:00
66 #'EAST' => '-0600', # Easter Island Standard Time UTC-06:00
67 #'EAT' => '+0300', # East Africa Time UTC+03:00
68 #'ECT' => '-0400', # Eastern Caribbean Time (does not recognise DST) UTC-04:00
69 #'ECT' => '-0500', # Ecuador Time UTC-05:00
70 'EDT' => '-0400', # Eastern Daylight Time (North America) UTC-04:00
71 #'EEDT' => '+0300', # Eastern European Daylight Time UTC+03:00
72 #'EEST' => '+0300', # Eastern European Summer Time UTC+03:00
73 #'EET' => '+0200', # Eastern European Time UTC+02:00
74 'EST' => '+0500', # Eastern Standard Time (North America) UTC-05:00
75 #'FJT' => '+1200', # Fiji Time UTC+12:00
76 #'FKST' => '-0400', # Falkland Islands Standard Time UTC-04:00
77 #'GALT' => '-0600', # Galapagos Time UTC-06:00
78 #'GET' => '+0400', # Georgia Standard Time UTC+04:00
79 #'GFT' => '-0300', # French Guiana Time UTC-03:00
80 #'GILT' => '+1200', # Gilbert Island Time UTC+12:00
81 #'GIT' => '-0900', # Gambier Island Time UTC-09:00
82 'GMT' => '+0000', # Greenwich Mean Time UTC
83 #'GST' => '-0200', # South Georgia and the South Sandwich Islands UTC-02:00
84 #'GYT' => '-0400', # Guyana Time UTC-04:00
85 'HADT' => '-0900', # Hawaii-Aleutian Daylight Time UTC-09:00
86 'HAST' => '-1000', # Hawaii-Aleutian Standard Time UTC-10:00
87 #'HKT' => '+0800', # Hong Kong Time UTC+08:00
88 #'HMT' => '+0500', # Heard and McDonald Islands Time UTC+05:00
89 'HST' => '-1000', # Hawaii Standard Time UTC-10:00
90 #'IRKT' => '+0800', # Irkutsk Time UTC+08:00
91 #'IRST' => '+0330', # Iran Standard Time UTC+03:30
92 #'IST' => '+0530', # Indian Standard Time UTC+05:30
93 #'IST' => '+0100', # Irish Summer Time UTC+01:00
94 #'IST' => '+0200', # Israel Standard Time UTC+02:00
95 'JST' => '+0900', # Japan Standard Time UTC+09:00
96 #'KRAT' => '+0700', # Krasnoyarsk Time UTC+07:00
97 #'KST' => '+0900', # Korea Standard Time UTC+09:00
98 #'LHST' => '+1030', # Lord Howe Standard Time UTC+10:30
99 #'LINT' => '+1400', # Line Islands Time UTC+14:00
100 #'MAGT' => '+1100', # Magadan Time UTC+11:00
101 'MDT' => '-0600', # Mountain Daylight Time(North America) UTC-06:00
102 #'MIT' => '-0930', # Marquesas Islands Time UTC-09:30
103 #'MSD' => '+0400', # Moscow Summer Time UTC+04:00
104 #'MSK' => '+0300', # Moscow Standard Time UTC+03:00
105 #'MST' => '+0800', # Malaysian Standard Time UTC+08:00
106 'MST' => '-0700', # Mountain Standard Time(North America) UTC-07:00
107 #'MST' => '+0630', # Myanmar Standard Time UTC+06:30
108 #'MUT' => '+0400', # Mauritius Time UTC+04:00
109 #'NDT' => '-0230', # Newfoundland Daylight Time UTC-02:30
110 #'NFT' => '+1130', # Norfolk Time[1] UTC+11:30
111 #'NPT' => '+0545', # Nepal Time UTC+05:45
112 #'NST' => '-0330', # Newfoundland Standard Time UTC-03:30
113 #'NT' => '-0330', # Newfoundland Time UTC-03:30
114 #'OMST' => '+0600', # Omsk Time UTC+06:00
115 'PDT' => '-0700', # Pacific Daylight Time(North America) UTC-07:00
116 #'PETT' => '+1200', # Kamchatka Time UTC+12:00
117 #'PHOT' => '+1300', # Phoenix Island Time UTC+13:00
118 #'PKT' => '+0500', # Pakistan Standard Time UTC+05:00
119 'PST' => '-0800', # Pacific Standard Time (North America) UTC-08:00
120 #'PST' => '+0800', # Philippine Standard Time UTC+08:00
121 #'RET' => '+0400', # Reunion Time UTC+04:00
122 #'SAMT' => '+0400', # Samara Time UTC+04:00
123 #'SAST' => '+0200', # South African Standard Time UTC+02:00
124 #'SBT' => '+1100', # Solomon Islands Time UTC+11:00
125 #'SCT' => '+0400', # Seychelles Time UTC+04:00
126 #'SLT' => '+0530', # Sri Lanka Time UTC+05:30
127 #'SST' => '-1100', # Samoa Standard Time UTC-11:00
128 #'SST' => '+0800', # Singapore Standard Time UTC+08:00
129 #'TAHT' => '-1000', # Tahiti Time UTC-10:00
130 #'THA' => '+0700', # Thailand Standard Time UTC+07:00
131 'UT' => '-0000', # Coordinated Universal Time UTC
132 'UTC' => '-0000', # Coordinated Universal Time UTC
133 #'UYST' => '-0200', # Uruguay Summer Time UTC-02:00
134 #'UYT' => '-0300', # Uruguay Standard Time UTC-03:00
135 #'VET' => '-0430', # Venezuelan Standard Time UTC-04:30
136 #'VLAT' => '+1000', # Vladivostok Time UTC+10:00
137 #'WAT' => '+0100', # West Africa Time UTC+01:00
138 #'WEDT' => '+0100', # Western European Daylight Time UTC+01:00
139 #'WEST' => '+0100', # Western European Summer Time UTC+01:00
140 #'WET' => '-0000', # Western European Time UTC
141 #'YAKT' => '+0900', # Yakutsk Time UTC+09:00
142 #'YEKT' => '+0500', # Yekaterinburg Time UTC+05:00
143 87 };
144  
145 3 ▶sub monthname {
Subroutine monthname: called CC=3 SCAR=11.0
Pod undocumented
146 # Month name list
147 # @param [Integer] argv1 Require full name or not
148 # @return [Array, String] Month name list or month name
149 # @example Get the names of each month
150 # monthname() #=> ['Jan', 'Feb', ...]
151 # monthname(1) #=> ['January', 'February', 'March', ...]
152 3 my $class = shift;
153 3 ▶ my $argv1 = shift // 0;
Condition100%2/2
shift() // 0
l!l
21
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
154 3 ▶ return MonthName->{ $argv1 ? 'full' : 'abbr' };
Branch: 1 branch
BranchTrueFalseTotal
$argv1 ? : 1 2 3
155 }
156  
157 3671 ▶sub parse {
Subroutine parse: called CC=54 SCAR=41.4
Pod documented
158 # Parse date string; strptime() wrapper
159 # @param [String] argv1 Date string
160 # @return [String] Converted date string
161 # @see http://en.wikipedia.org/wiki/ISO_8601
162 # @see http://www.ietf.org/rfc/rfc3339.txt
163 # @example Parse date string and convert to generic format string
164 # parse("2015-11-03T23:34:45 Tue") #=> Tue, 3 Nov 2015 23:34:45 +0900
165 # parse("Tue, Nov 3 2015 2:2:2") #=> Tue, 3 Nov 2015 02:02:02 +0900
166 3671 my $class = shift;
167 3671 ▶ my $argv1 = shift || return "";
Condition100%2/2
shift() || (return '')
l!l
36701
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
168  
169 # "Apr 29", -> "Apr 29" "Thu,13" -> "Thu, 13"
170 3670 my $datestring = $argv1; s/[,](\d+)/, $1/, s/(\d{1,2}),/$1/ for $datestring;
171 3670 my @timetokens = split(' ', $datestring);
172 3670 my $parseddate = ''; # [String] Canonified Date/Time string
173 3670 my $afternoon1 = 0; # [Integer] After noon flag
174 3670 my $altervalue = {}; # [Hash] To store alternative values
175 3670 my $v = {
176 'Y' => "", # [Integer] Year
177 'M' => "", # [String] Month Abbr.
178 'd' => "", # [Integer] Day
179 'a' => "", # [String] Day of week, Abbr.
180 'T' => "", # [String] Time
181 'z' => "", # [Integer] Timezone offset
182 };
183  
184 3670 for my $p ( @timetokens ) {
185 # Parse each piece of time
186 22018 ▶ if( $p =~ /\A[A-Z][a-z]{2,}[,]?\z/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($p =~ /\A[A-Z][a-z]{2,}[,]?\z/u) { } 7121 14897 22018
elsif ($p =~ /\A\d{1,4}\z/u) { } 7254 7643 14897
elsif ($p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/u or $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/u) { } 3666 3977 7643
elsif ($p =~ /\A([0-2]\d):([0-5]\d)\z/u) { } 2 3975 3977
elsif ($p =~ /\A(\d\d?):(\d\d?)\z/u) { } 1 3974 3975
elsif (lc $p eq 'am' or lc $p eq 'pm') { } 12 3962 3974
187 # Day of week or Day of week; Thu, Apr, ...
188 7121 ▶ substr($p, -1, 1, '') if substr($p, -1, 1) eq ','; # "Thu," => "Thu"
Branch: 1 branch
BranchTrueFalseTotal
if substr($p, -1, 1) eq "," 3481 3640 7121
189 7121 ▶ $p = substr($p, 0, 3) if length $p > 3;
Branch: 1 branch
BranchTrueFalseTotal
if length $p > 3 6 7115 7121
190  
191 7121 ▶ if( grep { $p eq $_ } DayOfWeek->{'abbr'}->@* ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$p eq $_;} @{{abbr => ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], full => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']}->{'abbr'}}) { } 3492 3629 7121
elsif (grep {$p eq $_;} @{{abbr => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], full => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']}->{'abbr'}}) { } 3626 3 3629
192 # Day of week; Mon, Thu, Sun,...
193 3492 $v->{'a'} = $p;
194  
195 43548 } elsif( grep { $p eq $_ } MonthName->{'abbr'}->@* ) {
196 # Month name abbr.; Apr, May, ...
197 3626 $v->{'M'} = $p;
198 }
199 } elsif( $p =~ /\A\d{1,4}\z/ ) {
200 # Year or Day; 2005, 31, 04, 1, ...
201 7254 $p = int $p;
202 7254 ▶ if( $p > 31 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p > 31) { } 3582 3672 7254
203 # The piece is the value of an year
204 3582 $v->{'Y'} = $p;
205  
206 } else {
207 # The piece is the value of a day
208 3672 ▶ if( $v->{'d'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{'d'}) { } 46 3626 3672
209 # 2-digit year?
210 46 ▶ $altervalue->{'Y'} = $p unless $v->{'Y'};
Branch: 1 branch
BranchTrueFalseTotal
unless $v->{"Y"} 46 0 46
211  
212 } else {
213 # The value is "day"
214 3626 $v->{'d'} = $p;
215 }
216 }
217 ▶ } elsif( $p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/ || $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/ ) {
Condition100%3/3
$p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/u or $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/u
l!l&&r!l&&!r
3640263977
MC/DC100%2/2
$p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/u or $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/u
$p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/u $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/u
Truth table100%3/3
A or B
A= $p =~ /\A([0-2]\d):([0-5]\d):([0-5]\d)\z/uB= $p =~ /\A(\d{1,2})[-:](\d{1,2})[-:](\d{1,2})\z/u
ABresult
1X1
011
000
218 # Time; 12:34:56, 03:14:15, ...
219 # Arrival-Date: 2014-03-26 00-01-19
220 3666 ▶ $v->{'T'} = sprintf("%02d:%02d:%02d", $1, $2, $3) if( $1 < 24 && $2 < 60 && $3 < 60 );
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 24 and $2 < 60 and $3 < 60 3663 3 3666
Condition100%6/6
$1 < 24 and $2 < 60 and $3 < 60
!ll&&!rl&&r
213663
$1 < 24 and $2 < 60
!ll&&!rl&&r
113664
MC/DC100%3/3
$1 < 24 and $2 < 60 and $3 < 60
$1 < 24 $2 < 60 $3 < 60
Truth table100%4/4
A and B and C
A= $1 < 24B= $2 < 60C= $3 < 60
ABCresult
0XX0
10X0
1100
1111
221  
222 } elsif( $p =~ /\A([0-2]\d):([0-5]\d)\z/ ) {
223 # Time; 12:34 => 12:34:00
224 2 ▶ $v->{'T'} = sprintf("%02d:%02d:00", $1, $2) if( $1 < 24 && $2 < 60 );
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 24 and $2 < 60 2 0 2
Condition33%1/3
$1 < 24 and $2 < 60
!ll&&!rl&&r
002
MC/DC0%0/2
$1 < 24 and $2 < 60
$1 < 24 $2 < 60
Truth table33%1/3
A and B
A= $1 < 24B= $2 < 60
ABresult
0X0
100
111
225  
226 } elsif( $p =~ /\A(\d\d?):(\d\d?)\z/ ) {
227 # Time: 1:4 => 01:04:00
228 1 $v->{'T'} = sprintf("%02d:%02d:00", $1, $2);
229  
230 ▶ } elsif( lc $p eq 'am' || lc $p eq 'pm' ) {
Condition66%2/3
lc $p eq "am" or lc $p eq "pm"
l!l&&r!l&&!r
0123962
MC/DC50%1/2
lc $p eq "am" or lc $p eq "pm"
lc $p eq "am" lc $p eq "pm"
Truth table66%2/3
A or B
A= lc $p eq "am"B= lc $p eq "pm"
ABresult
1X1
011
000
231 # AM or PM
232 12 $afternoon1 = 1;
233  
234 } else {
235 # Timezone offset and others
236 3962 ▶ if( $p =~ /\A[-+][01]\d{3}\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ /\A[-+][01]\d{3}\z/u) { } 3548 414 3962
elsif ($p =~ /\A[(]?[A-Z]{2,5}[)]?\z/u) { } 358 56 414
237 # Timezone offset; +0000, +0900, -1000, ...
238 3548 ▶ $v->{'z'} ||= $p;
Condition33%1/3
$v->{"z"} ||= $p
l!l&&r!l&&!r
035480
MC/DC0%0/2
$v->{"z"} ||= $p
$v->{"z"} $p
Truth table33%1/3
A ||= B
A= $v->{"z"}B= $p
ABresult
1X1
011
000
239  
240 } elsif( $p =~ /\A[(]?[A-Z]{2,5}[)]?\z/ ) {
241 # Timezone abbreviation; JST, GMT, UTC, ...
242 358 ▶ $v->{'z'} ||= __PACKAGE__->abbr2tz($p) || '+0000';
Condition60%3/5
$v->{"z"} ||= __PACKAGE__->abbr2tz($p) || "+0000"
l!l&&r!l&&!r
291670
__PACKAGE__->abbr2tz($p) || '+0000'
l!l
670
MC/DC0%0/2
$v->{"z"} ||= __PACKAGE__->abbr2tz($p) || "+0000"
$v->{"z"} __PACKAGE__->abbr2tz($p)
Truth table66%2/3
A ||= B
A= $v->{"z"}B= __PACKAGE__->abbr2tz($p)
ABresult
1X1
011
000
243  
244 } else {
245 # Other date format
246 56 ▶ if( $p =~ m|\A(\d{4})[-/](\d{1,2})[-/](\d{1,2})\z| ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($p =~ m[\A(\d{4})[-/](\d{1,2})[-/](\d{1,2})\z]u) { } 35 21 56
elsif ($p =~ m[\A(\d{4})[-/](\d{1,2})[-/](\d{1,2})T([0-2]\d):([0-5]\d):([0-5]\d)\z]u) { } 1 20 21
elsif ($p =~ m[\A(\d{1,2})/(\d{1,2})/(\d{1,2})\z]u) { } 6 14 20
elsif ($p =~ m[\A(\d{1,2})[-/](\d{1,2})[-/](\d{4})]u) { } 1 13 14
247 # Mail.app(MacOS X)'s faked Bounce, Arrival-Date: 2010-06-18 17:17:52 +0900
248 35 $v->{'Y'} = int $1;
249 35 $v->{'M'} = MonthName->{'abbr'}->[int($2) - 1];
250 35 $v->{'d'} = int $3;
251  
252 } elsif( $p =~ m|\A(\d{4})[-/](\d{1,2})[-/](\d{1,2})T([0-2]\d):([0-5]\d):([0-5]\d)\z| ) {
253 # ISO 8601; 2000-04-29T01:23:45
254 1 $v->{'Y'} = int $1;
255 1 $v->{'M'} = MonthName->{'abbr'}->[int($2) - 1];
256 1 ▶ $v->{'d'} = int $3 if $3 < 32;
Branch: 1 branch
BranchTrueFalseTotal
if $3 < 32 1 0 1
257  
258 1 ▶ $v->{'T'} = sprintf("%02d:%02d:%02d", $4, $5, $6) if( $4 < 24 && $5 < 60 && $6 < 60 );
Branch: 1 branch
BranchTrueFalseTotal
if $4 < 24 and $5 < 60 and $6 < 60 1 0 1
Condition33%2/6
$4 < 24 and $5 < 60 and $6 < 60
!ll&&!rl&&r
001
$4 < 24 and $5 < 60
!ll&&!rl&&r
001
MC/DC0%0/3
$4 < 24 and $5 < 60 and $6 < 60
$4 < 24 $5 < 60 $6 < 60
Truth table25%1/4
A and B and C
A= $4 < 24B= $5 < 60C= $6 < 60
ABCresult
0XX0
10X0
1100
1111
259  
260 } elsif( $p =~ m|\A(\d{1,2})/(\d{1,2})/(\d{1,2})\z| ) {
261 # 4/29/01 11:34:45 PM
262 6 $v->{'M'} = MonthName->{'abbr'}->[int($1) - 1];
263 6 $v->{'d'} = int $2;
264 6 $v->{'Y'} = int($3) + 2000;
265 6 ▶ $v->{'Y'} -= 100 if $v->{'Y'} > Time::Piece->new->year() + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"Y"} > "Time::Piece"->new->year + 1 0 6 6
266  
267 } elsif( $p =~ m|\A(\d{1,2})[-/](\d{1,2})[-/](\d{4})| ) {
268 # 29-04-2017 22:22
269 1 ▶ $v->{'d'} = int $1 if $1 < 32;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 32 1 0 1
270 1 $v->{'M'} = MonthName->{'abbr'}->[int($2) - 1];
271 1 $v->{'Y'} = int($3);
272 }
273 }
274 }
275 } # End of while()
276  
277 3670 ▶ if( $v->{'T'} && $afternoon1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"T"} and $afternoon1) 12 3658 3670
Condition100%3/3
$v->{"T"} and $afternoon1
!ll&&!rl&&r
3365512
MC/DC100%2/2
$v->{"T"} and $afternoon1
$v->{"T"} $afternoon1
Truth table100%3/3
A and B
A= $v->{"T"}B= $afternoon1
ABresult
0X0
100
111
278 # +12
279 12 my $t0 = $v->{'T'};
280 12 my @t1 = split(':', $v->{'T'});
281 12 $v->{'T'} = sprintf("%02d:%02d:%02d", $t1[0] + 12, $t1[1], $t1[2]);
282 12 ▶ $v->{'T'} = $t0 if $t1[0] > 12;
Branch: 1 branch
BranchTrueFalseTotal
if $t1[0] > 12 1 11 12
283 }
284  
285 3670 ▶ $v->{'a'} ||= 'Thu'; # There is no day of week
Condition100%2/2
$v->{"a"} ||= "Thu"
l!l
3492178
MC/DC100%1/1
$v->{"a"} ||= "Thu"
$v->{"a"}
Truth table100%2/2
A
A= $v->{"a"}
Aresult
11
00
286 3670 ▶ $v->{'Y'} += 1900 if length($v->{'Y'}) > 0 && int($v->{'Y'}) < 200; # 99 -> 1999, 102 -> 2002
Branch: 1 branch
BranchTrueFalseTotal
if length $v->{"Y"} > 0 and int $v->{"Y"} < 200 2 3668 3670
Condition100%3/3
length $v->{"Y"} > 0 and int $v->{"Y"} < 200
!ll&&!rl&&r
4636222
MC/DC100%2/2
length $v->{"Y"} > 0 and int $v->{"Y"} < 200
length $v->{"Y"} > 0 int $v->{"Y"} < 200
Truth table100%3/3
A and B
A= length $v->{"Y"} > 0B= int $v->{"Y"} < 200
ABresult
0X0
100
111
287 3670 ▶ $v->{'z'} ||= __PACKAGE__->second2tz(Time::Piece->new->tzoffset);
Condition66%2/3
$v->{"z"} ||= __PACKAGE__->second2tz("Time::Piece"->new->tzoffset)
l!l&&r!l&&!r
3615550
MC/DC0%0/2
$v->{"z"} ||= __PACKAGE__->second2tz("Time::Piece"->new->tzoffset)
$v->{"z"} __PACKAGE__->second2tz("Time::Piece"->new->tzoffset)
Truth table66%2/3
A ||= B
A= $v->{"z"}B= __PACKAGE__->second2tz("Time::Piece"->new->tzoffset)
ABresult
1X1
011
000
288  
289 # Adjust 2-digit Year
290 3670 ▶ if( exists $altervalue->{'Y'} && ! $v->{'Y'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $altervalue->{"Y"} and not $v->{"Y"}) 46 3624 3670
Condition66%2/3
exists $altervalue->{"Y"} and not $v->{"Y"}
!ll&&!rl&&r
3624046
MC/DC50%1/2
exists $altervalue->{"Y"} and not $v->{"Y"}
exists $altervalue->{"Y"} not $v->{"Y"}
Truth table66%2/3
A and not(B)
A= exists $altervalue->{"Y"}B= not $v->{"Y"}
ABresult
0X0
100
111
291 # Check alternative value(Year)
292 46 ▶ if( $altervalue->{'Y'} >= 82 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($altervalue->{'Y'} >= 82) { } 0 46 46
293 # SMTP was born in 1982
294 0 ▶ $v->{'Y'} ||= 1900 + $altervalue->{'Y'};
Condition0%0/3
$v->{"Y"} ||= 1900 + $altervalue->{"Y"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$v->{"Y"} ||= 1900 + $altervalue->{"Y"}
$v->{"Y"} 1900 + $altervalue->{"Y"}
Truth table0%0/3
A ||= B
A= $v->{"Y"}B= 1900 + $altervalue->{"Y"}
ABresult
1X1
011
000
295  
296 } else {
297 # 20XX
298 46 ▶ $v->{'Y'} ||= 2000 + $altervalue->{'Y'};
Condition33%1/3
$v->{"Y"} ||= 2000 + $altervalue->{"Y"}
l!l&&r!l&&!r
0460
MC/DC0%0/2
$v->{"Y"} ||= 2000 + $altervalue->{"Y"}
$v->{"Y"} 2000 + $altervalue->{"Y"}
Truth table33%1/3
A ||= B
A= $v->{"Y"}B= 2000 + $altervalue->{"Y"}
ABresult
1X1
011
000
299 }
300 }
301  
302 # Check each piece
303 3670 ▶ if( grep { $_ eq "" } values %$v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "";} values %$v) 5 3665 3670
304 # Strange date format
305 5 printf(STDERR " ***warning: Strange date format [%s]\n", $datestring);
306 5 return "";
307 }
308  
309 # Build date string
310 # Thu, 29 Apr 2004 10:01:11 +0900
311 3665 ▶ return "" if $v->{'Y'} < 1902 || $v->{'Y'} > 2037; # -(2^31) ~ (2^31)
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"Y"} < 1902 or $v->{"Y"} > 2037 2 3663 3665
Condition100%3/3
$v->{"Y"} < 1902 or $v->{"Y"} > 2037
l!l&&r!l&&!r
113663
MC/DC100%2/2
$v->{"Y"} < 1902 or $v->{"Y"} > 2037
$v->{"Y"} < 1902 $v->{"Y"} > 2037
Truth table100%3/3
A or B
A= $v->{"Y"} < 1902B= $v->{"Y"} > 2037
ABresult
1X1
011
000
312 3663 return sprintf("%s, %s %s %s %s %s", $v->{'a'}, $v->{'d'}, $v->{'M'}, $v->{'Y'}, $v->{'T'}, $v->{'z'});
313 }
314  
315 77 ▶sub abbr2tz {
Subroutine abbr2tz: called CC=2 SCAR=6.9
Pod documented
316 # Abbreviation -> Tiemzone
317 # @param [String] argv1 Abbr. e.g.) JST, GMT, PDT
318 # @return [String] +0900, +0000, -0600 or an empty string if the argument is invalid
319 # format or not supported abbreviation
320 # @example Get the timezone string of "JST"
321 # abbr2tz('JST') #=> '+0900'
322 77 my $class = shift;
323 77 ▶ my $argv1 = shift || return "";
Condition100%2/2
shift() || (return '')
l!l
761
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
324 76 return TimeZones->{ $argv1 };
325 }
326  
327 3714 ▶sub tz2second {
Subroutine tz2second: called CC=6 SCAR=17.9
Pod undocumented
328 # Convert to second
329 # @param [String] argv1 Timezone string e.g) +0900
330 # @return [Integer] Seconds or -1 it the argument is invalid format string
331 # @see second2tz
332 # @example Convert '+0900' to seconds
333 # tz2second('+0900') #=> 32400
334 3714 my $class = shift;
335 3714 ▶ my $argv1 = shift || return -1;
Condition100%2/2
shift() || (return -1)
l!l
368826
MC/DC100%1/1
shift() || (return -1)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
336  
337 3688 ▶ if( $argv1 =~ /\A([-+])(\d)(\d)(\d{2})\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($argv1 =~ /\A([-+])(\d)(\d)(\d{2})\z/u) { } 3640 48 3688
elsif ($argv1 =~ /\A[A-Za-z]+\z/u) { } 1 47 48
338 3640 my $ztime = 0;
339 3640 my $digit = {
340 'operator' => $1,
341 'hour-10' => $2,
342 'hour-01' => $3,
343 'minutes' => $4
344 };
345 3640 $ztime += ( $digit->{'hour-10'} * 10 + $digit->{'hour-01'} ) * 3600;
346 3640 $ztime += ( $digit->{'minutes'} * 60 );
347 3640 ▶ $ztime *= -1 if $digit->{'operator'} eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $digit->{"operator"} eq "-" 690 2950 3640
348  
349 3640 ▶ return -1 if abs($ztime) > TZ_OFFSET;
Branch: 1 branch
BranchTrueFalseTotal
if abs $ztime > 54000 2 3638 3640
350 3638 return $ztime;
351  
352 } elsif( $argv1 =~ /\A[A-Za-z]+\z/ ) {
353 1 return __PACKAGE__->tz2second(TimeZones->{ $argv1 });
354  
355 } else {
356 47 return -1;
357 }
358 }
359  
360 64 ▶sub second2tz {
Subroutine second2tz: called CC=6 SCAR=18.0
Pod undocumented
361 # Convert to Timezone string
362 # @param [Integer] argv1 Second to be converted
363 # @return [String] Timezone offset string
364 # @see tz2second
365 # @example Get timezone offset string of specified seconds
366 # second2tz(12345) #=> '+0325'
367 64 my $class = shift;
368 64 ▶ my $argv1 = shift // return '+0000';
Condition100%2/2
shift() // (return "+0000")
l!l
631
MC/DC100%1/1
shift() // (return "+0000")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
369 63 my $digit = {'operator' => '+'};
370  
371 63 ▶ return '' if( ref($argv1) && ref($argv1) ne 'Time::Seconds' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $argv1 and ref $argv1 ne "Time::Seconds" 0 63 63
Condition66%2/3
ref $argv1 and ref $argv1 ne "Time::Seconds"
!ll&&!rl&&r
8550
MC/DC0%0/2
ref $argv1 and ref $argv1 ne "Time::Seconds"
ref $argv1 ref $argv1 ne "Time::Seconds"
Truth table66%2/3
A and B
A= ref $argv1B= ref $argv1 ne "Time::Seconds"
ABresult
0X0
100
111
372 63 ▶ return '' if( abs($argv1) > TZ_OFFSET ); # UTC+14 + 1(DST?)
Branch: 1 branch
BranchTrueFalseTotal
if abs $argv1 > 54000 2 61 63
373 61 ▶ $digit->{'operator'} = '-' if $argv1 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $argv1 < 0 2 59 61
374  
375 61 $digit->{'hours'} = int(abs($argv1) / 3600);
376 61 $digit->{'minutes'} = int((abs($argv1) % 3600) / 60);
377 61 return sprintf("%s%02d%02d", $digit->{'operator'}, $digit->{'hours'}, $digit->{'minutes'});
378 }
379  
380 87 1;
381 __END__
« Sisimai/Lhost/Courier.pm ↑ Summary Sisimai/Lhost/V5sendmail.pm »