Config/Date.pm

filter: Statementstmt 66.7% 587 / 879 Branchbran 51.3% 229 / 446 Conditioncond 38.6% 160 / 414 MC/DCmcdc 24.5% 56 / 228 Subroutinesub 81.8% 36 / 44 Podpod 87.5% 14 / 16 totaltotal 53.3% 1082 / 2027 CC 405 SCAR 68.2
CC
405
Cov
56%
parse_date_old
5112.0
_swap_manip_language_common
992.0
_month_num_day_str
462.0
CRAP 919.0
↑ Summary Config/Options.pm »
1 ###
2 ### Copyright (c) 2018 - 2026 Curtis Leach. All rights reserved.
3 ###
4 ### Module: Advanced::Config::Date
5  
6 =head1 NAME
7  
8 Advanced::Config::Date - Module for parsing dates for L<Advanced::Config>.
9  
10 =head1 SYNOPSIS
11  
12 use Advanced::Config::Date;
13 or
14 require Advanced::Config::Date;
15  
16 =head1 DESCRIPTION
17  
18 F<Advanced::Config::Date> is a helper module to L<Advanced::Config>. So it
19 should be very rare to directly call any methods defined by this module. But
20 it's perfectly OK to use this module directly if you wish.
21  
22 It's main job is to handle parsing dates passed in various formats and languages
23 while returning it in the standardized format of: S<YYYY-MM-DD>. Hiding all the
24 messy logic of how to interpret any given date string.
25  
26 =head1 MULTI-LANGUAGE SUPPORT
27  
28 By default this module only supports parsing B<English> language dates.
29  
30 But if you have the I<Date::Language> and/or I<Date::Manip> modules installed
31 you can ask for it to use another language supported by either of these modules
32 instead.
33  
34 You have to explicitly allow languages that require the use of I<Wide Chars>.
35 Otherwise they are not supported.
36  
37 If a language is defined in both modules, it will merge the data together.
38 Since both modules sometimes give extra information that can be useful in
39 parsing a date..
40  
41 =head1 FOUR-DIGIT VS TWO-DIGIT YEARS IN A DATE
42  
43 This module will accept both 4-digit and 2-digit years in the dates it parses.
44 But two-digit years are inherently ambiguous if you aren't given the expected
45 format up front. So 2-digit years generate more unreliability in the parsing
46 of any dates by this module.
47  
48 So when used by the L<Advanced::Config> module, that module gives you the
49 ability to turn two-digit years on or off. This is done via the B<Get Option>
50 "B<date_enable_yy>" which defaults to 0, B<not> allowing two-digit years.
51  
52 To help resolve ambiguity with numeric dates, there is an option "B<date_format>"
53 that tells the L<Advanced::Config> how to parse these dates. See the order
54 argument for I<parse_6_digit_date()> and I<parse_8_digit_date()> for how this
55 is done.
56  
57 Finally if you use "B<date_dl_conversion>" and module L<Date::Language> is
58 installed, it will enhance parse_date() with that module's str2time() parser.
59 So if this option was used, it doesn't make much sense to disable 2-digit years.
60 Since we can't turn off 2-digit year support for str2time().
61  
62 See L<Advanced::Config::Options> for more options telling how that module
63 controls how L<Advanced::Config> uses this module for parsing dates.
64  
65 Those options have no effect if you are calling these methods directly.
66  
67 =head1 FUNCTIONS
68  
69 =over 4
70  
71 =cut
72  
73 package Advanced::Config::Date;
74  
75 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 29 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 29 ▶use File::Glob qw (bsd_glob);
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 29 ▶use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
82 29 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 29 ▶use Fred::Fish::DBUG 2.09 qw / on_if_set ADVANCED_CONFIG_FISH /;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 29 $VERSION = "1.15";
86 29 @ISA = qw( Exporter );
87  
88 29 @EXPORT = qw( get_languages
89 swap_language
90 parse_date
91 adjust_future_cutoff
92 make_it_a_4_digit_year
93 parse_8_digit_date
94 parse_6_digit_date
95 init_special_date_arrays
96 _date_language_installed
97 _date_manip_installed
98 _validate_date_str
99 is_leap_year
100 calc_hundred_year_date
101 calc_day_of_week
102 convert_hyd_to_date_str
103 calc_day_of_year
104 adjust_date_str
105 );
106  
107 29 @EXPORT_OK = qw( );
108  
109 29 my $global_cutoff_date = 30; # Defaults to 30 years in the future ...
110  
111 # Thesee haahes tell which language modules are available ...
112 29 my %date_language_installed_languages;
113 my %date_manip_installed_languages;
114  
115 # ========================================================================
116 # Detects if the optional Date::Language module is available ...
117 # If it's not installed, you'll be unable to swap languages using it!
118 BEGIN
119 29 ▶{
Subroutine BEGIN: called CC=2 SCAR=6.9
120 29 eval {
121 29 local $SIG{__DIE__} = "";
122 29 require Date::Language;
123  
124 # Find out where it's installed
125 29 my $loc = $INC{"Date/Language.pm"};
126 29 $loc =~ s/[.]pm$//;
127  
128 29 my $search = File::Spec->catfile ($loc, "*.pm");
129  
130 # Get's the list of languages supported.
131 29 foreach my $f ( bsd_glob ($search) ) {
132 1044 my $module = (File::Spec->splitdir( $f ))[-1];
133 1044 $module =~ s/[.]pm$//;
134  
135 1044 my %data = ( Language => $module,
136 Module => "Date::Language::${module}" );
137 1044 $date_language_installed_languages{lc($module)} = \%data;
138 }
139 };
140 }
141  
142 # ========================================================================
143 # Detects if the optional Date::Manip module is available ...
144 # If it's not installed, you'll be unable to swap languages using it!
145 BEGIN
146 29 ▶{
Subroutine BEGIN: called CC=3 SCAR=19.2
147 29 eval {
148 29 local $SIG{__DIE__} = "";
149 29 require Date::Manip::Lang::index;
150 0 Date::Manip::Lang::index->import ();
151  
152 0 foreach my $k ( sort keys %Date::Manip::Lang::index::Lang ) {
153 0 my $mod = $Date::Manip::Lang::index::Lang{$k};
154 0 ▶ my $lang = ( $k eq $mod ) ? ucfirst ($mod) : $mod;
Branch: 1 branch
BranchTrueFalseTotal
$k eq $mod ? : 0 0 0
155 0 my $module = "Date::Manip::Lang::${mod}";
156  
157 0 my %data = ( Language => $lang, # A guess that's wrong sometimes
158 Module => $module );
159 0 $date_manip_installed_languages{lc ($k)} = \%data;
160 }
161 };
162  
163 # -------------------------------------------------------------
164 # Proves sometimes the module name is different from the
165 # real language name.
166 # -------------------------------------------------------------
167 # foreach my $k ( sort keys %date_manip_installed_languages ) {
168 # printf STDERR ("Key (%s) Language (%s)\n", $k, $date_manip_installed_languages{$k}->{Language});
169 # }
170 }
171  
172 # ========================================================================
173 # Hashes used to help validate/parse dates with ...
174 # Always keep the keys in lower case.
175  
176 # Using the values from Date::Language::English for initialization ...
177 # Hard coded here in case Date::Language wasn't installed ...
178  
179 # These hashes get rebuilt each time swap_language() is
180 # successfully called!
181 # ========================================================================
182 # Used by parse_date ();
183  
184 29 my %last_language_edit_flags;
185  
186 # Variants for the month names & days of month ...
187 # We hard code the initialization in case neither
188 # language module is installed locally.
189 29 my %Months;
190 29 my %Days;
191  
192 29 ▶BEGIN {
Subroutine BEGIN: called CC=8 SCAR=23.4
193 # Variants for the month names ...
194 29 %Months = (
195 # The USA Months spelled out ...
196 # Built from the @Date::Language::English::MoY array ...
197 "january" => 1, "february" => 2, "march" => 3,
198 "april" => 4, "may" => 5, "june" => 6,
199 "july" => 7, "august" => 8, "september" => 9,
200 "october" => 10, "november" => 11, "december" => 12,
201  
202 # The USA Months using 3 char abreviations ("may" not repeated!)
203 # Built from the @Date::Language::English::MoYs array ...
204 "jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4,
205 "jun" => 6, "jul" => 7, "aug" => 8,
206 "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12,
207  
208 # Months as a numeric value. If all digits, leading zeros will
209 # be removed before it's used as a key.
210 "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6,
211 "7" => 7, "8" => 8, "9" => 9, "10" => 10, "11" => 11, "12" => 12
212 );
213  
214 # variants for days of the month ...
215 29 %Days = (
216 "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5,
217 "6" => 6, "7" => 7, "8" => 8, "9" => 9, "10" => 10,
218 "11" => 11, "12" => 12, "13" => 13, "14" => 14, "15" => 15,
219 "16" => 16, "17" => 17, "18" => 18, "19" => 19, "20" => 20,
220 "21" => 21, "22" => 22, "23" => 23, "24" => 24, "25" => 25,
221 "26" => 26, "27" => 27, "28" => 28, "29" => 29, "30" => 30,
222 "31" => 31,
223  
224 # Built from the optional @Date::Language::English::Dsuf array ...
225 "1st" => 1, "2nd" => 2, "3rd" => 3, "4th" => 4, "5th" => 5,
226 "6th" => 6, "7th" => 7, "8th" => 8, "9th" => 9, "10th" => 10,
227 "11th" => 11, "12th" => 12, "13th" => 13, "14th" => 14, "15th" => 15,
228 "16th" => 16, "17th" => 17, "18th" => 18, "19th" => 19, "20th" => 20,
229 "21st" => 21, "22nd" => 22, "23rd" => 23, "24th" => 24, "25th" => 25,
230 "26th" => 26, "27th" => 27, "28th" => 28, "29th" => 29, "30th" => 30,
231 "31st" => 31,
232  
233 # From Date::Manip::Lang::english::Language->{nth} arrays ...
234 'first' => -1, 'second' => -2, 'third' => -3,
235 'fourth' => -4, 'fifth' => -5, 'sixth' => -6,
236 'seventh' => -7, 'eighth' => -8, 'ninth' => -9,
237 'tenth' => -10, 'eleventh' => -11, 'twelfth' => -12,
238 'thirteenth' => -13, 'fourteenth' => -14, 'fifteenth' => -15,
239 'sixteenth' => -16, 'seventeenth' => -17, 'eighteenth' => -18,
240 'nineteenth' => -19, 'twentieth' => -20, 'twenty-first' => -21,
241 'twenty-second' => -22, 'twenty-third' => -23, 'twenty-fourth' => -24,
242 'twenty-fifth' => -25, 'twenty-sixth' => -26, 'twenty-seventh' => -27,
243 'twenty-eighth' => -28, 'twenty-ninth' => -29, 'thirtieth' => -30,
244 'thirty-first' => -31,
245  
246 # From Date::Manip::Lang::english::Language->{nth} arrays ...
247 'one' => -1, 'two' => -2, 'three' => -3,
248 'four' => -4, 'five' => -5, 'six' => -6,
249 'seven' => -7, 'eight' => -8, 'nine' => -9,
250 'ten' => -10, 'eleven' => -11, 'twelve' => -12,
251 'thirteen' => -13, 'fourteen' => -14, 'fifteen' => -15,
252 'sixteen' => -16, 'seventeen' => -17, 'eighteen' => -18,
253 'nineteen' => -19, 'twenty' => -20, 'twenty-one' => -21,
254 'twenty-two' => -22, 'twenty-three' => -23, 'twenty-four' => -24,
255 'twenty-five' => -25, 'twenty-six' => -26, 'twenty-seven' => -27,
256 'twenty-eight' => -28, 'twenty-nine' => -29, 'thirty' => -30,
257 'thirty-one' => -31,
258 );
259  
260 29 my $date_manip_installed_flag = keys %date_manip_installed_languages;
261 29 my $date_language_installed_flag = keys %date_language_installed_languages;
262  
263 # Tells what to do about the negative values in the hashes ...
264 29 ▶ my $flip = $date_manip_installed_flag || (! $date_language_installed_flag);
Condition33%1/3
$date_manip_installed_flag || !$date_language_installed_flag
l!l&&r!l&&!r
0029
MC/DC0%0/2
$date_manip_installed_flag || !$date_language_installed_flag
$date_manip_installed_flag !$date_language_installed_flag
Truth table33%1/3
A || not(B)
A= $date_manip_installed_flagB= !$date_language_installed_flag
ABresult
1X1
011
000
265  
266  
267 29 $last_language_edit_flags{language} = "English";
268  
269 29 $last_language_edit_flags{month_period} = 0;;
270 29 $last_language_edit_flags{dsuf_period} = 0;
271 29 $last_language_edit_flags{dow_period} = 0;;
272  
273 29 foreach ( keys %Months ) {
274 1015 ▶ next if ( $Months{$_} > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $Months{$_} > 0 1015 0 1015
275 0 ▶ if ( $flip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flip) { } 0 0 0
276 0 $Months{$_} = abs ($Months{$_});
277 } else {
278 0 delete $Months{$_};
279 }
280 }
281  
282 29 foreach ( keys %Days ) {
283 3596 ▶ next if ( $Days{$_} > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $Days{$_} > 0 1798 1798 3596
284 1798 ▶ if ( $flip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flip) { } 0 1798 1798
285 0 $Days{$_} = abs ($Days{$_});
286 } else {
287 1798 delete $Days{$_};
288 }
289 }
290 }
291  
292 # How many days per month ... (non-leap year)
293 # ---------------------> J F M A M J J A S O N D
294 29 my @days_in_months = ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
295  
296  
297 # Updated by: init_special_date_arrays() ...
298 # May be for a different language than the above hashes ...
299 29 my $prev_array_lang = "English";
300 29 my @gMoY = qw ( January February March April May June
301 July August September October November December );
302 29 my @gMoYs = map { uc (substr($_,0,3)) } @gMoY;
303 29 my @gDsuf = sort { my ($x,$y) = ($a,$b); $x=~s/\D+$//; $y=~s/\D+$//; $x<=>$y } grep (/^\d+\D+$/, keys %Days, "0th");
304 29 my @gDoW = qw( Sunday Monday Tuesday Wednesday Thursday Friday Saturday );
305 29 my @gDoWs = map { uc (substr($_,0,3)) } @gDoW;
306  
307  
308 # ==============================================================
309 # Not in pod on purpose. Only added to simplify test cases.
310 sub _date_language_installed
311 6 ▶{
Subroutine _date_language_installed: called CC=1 SCAR=0.0
312 6 return ( scalar (keys %date_language_installed_languages) );
313 }
314  
315 # ==============================================================
316 # Not in pod on purpose. Only added to simplify test cases.
317 sub _date_manip_installed
318 0 ▶{
Subroutine _date_manip_installed: not called CC=1 SCAR=6.9
319 0 return ( scalar (keys %date_manip_installed_languages) );
320 }
321  
322 # ==============================================================
323  
324 =item @languages = get_languages ( );
325  
326 This module returns a sorted list of languages supported by this module
327 for the parsing of date strings.
328  
329 If neither L<Date::Language> and/or L<Date::Manip> are installed, only
330 I<English> is supported and you'll be unable to swap languages.
331  
332 Both modules are used since each language module supports a different
333 set of languages with a lot of overlap between them.
334  
335 Also L<Date::Manip> supports common aliases for some languages. These
336 aliases appear in lower case. When these aliases are used by
337 swap_language, it returns the real underlying language instead of
338 the alias.
339  
340 =cut
341  
342 sub get_languages
343 0 ▶{
Subroutine get_languages: not called CC=5 SCAR=34.0
Pod documented
344 0 DBUG_ENTER_FUNC ( @_ );
345  
346 0 my %languages;
347  
348 # For Date::Language ... (straight forward)
349 0 foreach my $k1 ( keys %date_language_installed_languages ) {
350 0 my $lang = $date_language_installed_languages{$k1}->{Language};
351 0 $languages{$lang} = 1;
352 }
353  
354 # For Date::Manip ... (a bit messy)
355 # Messy since we can't verify the language without 1st loading it!
356 0 foreach my $k1 ( keys %date_manip_installed_languages ) {
357 0 my $lang = $date_manip_installed_languages{$k1}->{Language};
358 0 ▶ my $k2 = ($k1 eq lc($lang)) ? $lang : $k1;
Branch: 1 branch
BranchTrueFalseTotal
$k1 eq lc $lang ? : 0 0 0
359 0 $languages{$k2} = 1;
360 }
361  
362 0 ▶ if ( scalar ( keys %languages ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %languages == 0) 0 0 0
363 0 $languages{English} = 1;
364 }
365  
366 0 DBUG_RETURN ( sort keys %languages );
367 }
368  
369 # ==============================================================
370 # Done this way to the warning goes to fish no matter what.
371 sub _warn_msg
372 4 ▶{
Subroutine _warn_msg: called CC=2 SCAR=6.9
373 4 DBUG_ENTER_FUNC ( @_ );
374 4 my $ok = shift;
375 4 my $msg = shift;
376 4 ▶ if ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 2 2 4
377 2 warn "==> ${msg}\n";
378 }
379 4 DBUG_VOID_RETURN ();
380 }
381  
382 # ==============================================================
383 # No POD on purpose ...
384 # Does some common logic for swap_language() & init_special_date_arrays().
385 # Requires knowledge of the internals to Date::Language::<language>
386 # in order to work.
387 # This method should avoid referencing any global variables!
388 # Returns: undef or the references to the 5 arrays!
389  
390 sub _swap_lang_common
391 116 ▶{
Subroutine _swap_lang_common: called CC=25 SCAR=33.7
392 116 DBUG_ENTER_FUNC ( @_ );
393 116 my $lang_ref = shift;
394 116 my $warn_ok = shift;
395 116 ▶ my $allow_wide = shift || 0;
Condition100%2/2
shift() || 0
l!l
9323
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
396  
397 116 my $base = "Date::Language";
398 116 my $lang = $lang_ref->{Language};
399 116 my $module = $lang_ref->{Module};
400  
401 116 my %issues;
402  
403 # Check if the requested language module exists ...
404 {
405 116 local $SIG{__DIE__} = "";
406 116 my $sts = eval "require ${module}";
407 116 ▶ unless ( $sts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sts) 0 116 116
408 0 _warn_msg ( $warn_ok, "${base} doesn't recognize '${lang}' as valid!" );
409 0 return DBUG_RETURN ( undef, undef, undef, undef, undef, \%issues );
410 }
411 }
412  
413 # @Dsuf isn't always available for some modules & buggy for others.
414 116 my @lMoY = eval "\@${module}::MoY"; # The fully spelled out Months.
415 116 my @lMoYs = eval "\@${module}::MoYs"; # The legal Abbreviations.
416 116 my @lDsuf = eval "\@${module}::Dsuf"; # The suffix for the Day of Month.
417 116 my @lDoW = eval "\@${module}::DoW"; # The Day of Week.
418 116 my @lDoWs = eval "\@${module}::DoWs"; # The Day of Week Abbreviations.
419  
420 # Detects Windows bug caused by case insensitive OS.
421 # Where the OS says the file exists, but it doesn't match the package name.
422 # Ex: Date::Language::Greek vs Date::Language::greek
423 116 ▶ if ( $#lMoY == -1 && $#lMoYs == -1 && $#lDsuf == -1 && $#lDoW == -1 && $#lDoWs == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#lMoY == -1 and $#lMoYs == -1 and $#lDsuf == -1 and $#lDoW == -1 and $#lDoWs == -1) 0 116 116
Condition33%4/12
$#lMoY == -1 and $#lMoYs == -1 and $#lDsuf == -1 and $#lDoW == -1 and $#lDoWs == -1
!ll&&!rl&&r
11600
$#lMoY == -1 and $#lMoYs == -1 and $#lDsuf == -1 and $#lDoW == -1
!ll&&!rl&&r
11600
$#lMoY == -1 and $#lMoYs == -1 and $#lDsuf == -1
!ll&&!rl&&r
11600
$#lMoY == -1 and $#lMoYs == -1
!ll&&!rl&&r
11600
MC/DC0%0/5
$#lMoY == -1 and $#lMoYs == -1 and $#lDsuf == -1 and $#lDoW == -1 and $#lDoWs == -1
$#lMoY == -1 $#lMoYs == -1 $#lDsuf == -1 $#lDoW == -1 $#lDoWs == -1
Truth table16%1/6
A and B and C and D and E
A= $#lMoY == -1B= $#lMoYs == -1C= $#lDsuf == -1D= $#lDoW == -1E= $#lDoWs == -1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
424 0 _warn_msg ( $warn_ok, "${base} doesn't recognize '${lang}' as valid due to case!" );
425 0 return DBUG_RETURN ( undef, undef, undef, undef, undef, \%issues );
426 }
427  
428 # Add the missing end of the month for quite a few Dsuf!
429 # Uses the suffixes from the 20's.
430 116 my $num = @lDsuf;
431 116 ▶ if ( $num > 29 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 29) 89 27 116
432 89 my $fix = $num % 10;
433 89 foreach ( $num..31 ) {
434 47 my $idx = $_ - $num + 20 + $fix;
435 47 $lDsuf[$_] = $lDsuf[$idx];
436 47 DBUG_PRINT ("FIX", "lDsuf[%d] = lDsuf[%d] = %s (%s)",
437 $_, $idx, $lDsuf[$_], $lang);
438 }
439 }
440  
441 # --------------------------------------------------
442 # Check if Unicode/Wide Chars were used ...
443 116 my $wide_flag = 0;
444 116 foreach ( @lMoY, @lMoYs, @lDsuf, @lDoW, @lDoWs ) {
445 # my $wide = utf8::is_utf8 ($_) || 0;
446 7277 ▶ my $wide = ( $_ =~ m/[^\x00-\xff]/ ) || 0; # m/[^\x00-\x7f]/ doesn't completely work!
Condition100%2/2
$_ =~ /[^\x00-\xff]/ || 0
l!l
10316246
MC/DC100%1/1
$_ =~ /[^\x00-\xff]/ || 0
$_ =~ /[^\x00-\xff]/
Truth table100%2/2
A
A= $_ =~ /[^\x00-\xff]/
Aresult
11
00
447 7277 ▶ if ( $wide ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wide) { } 1031 6246 7277
448 1031 $wide_flag = 1; # Multi-byte chars detected!
449 } else {
450 # Fix so uc()/lc() work for languages like German.
451 6246 utf8::encode ($_);
452 6246 utf8::decode ($_); # Sets utf8 flag ...
453  
454 # Are any of these common variants wide chars?
455 6246 ▶ if ( $_ =~ m/[^\x00-\xff]/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /[^\x00-\xff]/ or uc($_) =~ /[^\x00-\xff]/ or lc($_) =~ /[^\x00-\xff]/) 10 6236 6246
Condition66%4/6
$_ =~ /[^\x00-\xff]/ or uc($_) =~ /[^\x00-\xff]/ or lc($_) =~ /[^\x00-\xff]/
l!l&&r!l&&!r
1006236
$_ =~ /[^\x00-\xff]/ or uc($_) =~ /[^\x00-\xff]/
l!l&&r!l&&!r
0106236
MC/DC33%1/3
$_ =~ /[^\x00-\xff]/ or uc($_) =~ /[^\x00-\xff]/ or lc($_) =~ /[^\x00-\xff]/
$_ =~ /[^\x00-\xff]/ uc($_) =~ /[^\x00-\xff]/ lc($_) =~ /[^\x00-\xff]/
Truth table50%2/4
A or B or C
A= $_ =~ /[^\x00-\xff]/B= uc($_) =~ /[^\x00-\xff]/C= lc($_) =~ /[^\x00-\xff]/
ABCresult
1XX1
01X1
0011
0000
456 uc ($_) =~ m/[^\x00-\xff]/ ||
457 lc ($_) =~ m/[^\x00-\xff]/ ) {
458 10 $wide_flag = -1;
459 }
460 }
461 }
462  
463 116 $lang_ref->{Wide} = $wide_flag;
464  
465 116 ▶ if ( $wide_flag && ! $allow_wide ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wide_flag and not $allow_wide) 1 115 116
Condition100%3/3
$wide_flag and not $allow_wide
!ll&&!rl&&r
89261
MC/DC100%2/2
$wide_flag and not $allow_wide
$wide_flag not $allow_wide
Truth table100%3/3
A and not(B)
A= $wide_flagB= not $allow_wide
ABresult
0X0
100
111
466 1 _warn_msg ( $warn_ok, "'${lang}' uses Wide Chars. It's not currently enabled!" );
467 1 return DBUG_RETURN ( undef, undef, undef, undef, undef, \%issues );
468 }
469  
470 # Put in the number before the suffix ... (ie: nd => 2nd, rd => 3rd)
471 # Many langages built this array incorrectly & shorted it.
472 115 foreach ( 0..31 ) {
473 2894 ▶ last unless ( defined $lDsuf[$_] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lDsuf[$_] 26 2868 2894
474 2868 $lDsuf[$_] = $_ . $lDsuf[$_];
475 2868 ▶ $issues{dsuf_period} = 1 if ($lDsuf[$_] =~ m/[.]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $lDsuf[$_] =~ /[.]/ 128 2740 2868
476 }
477  
478 # Now check if any RegExp wild cards in the value ...
479 115 foreach ( @lMoY, @lMoYs ) {
480 2760 ▶ $issues{month_period} = 1 if ( $_ =~ m/[.]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /[.]/ 0 2760 2760
481 }
482  
483 115 foreach ( @lDoW, @lDoWs ) {
484 1610 ▶ $issues{dow_period} = 1 if ( $_ =~ m/[.]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /[.]/ 0 1610 1610
485 }
486  
487 115 DBUG_RETURN ( \@lMoY, \@lMoYs, \@lDsuf, \@lDoW, \@lDoWs, \%issues );
488 }
489  
490  
491 # ==============================================================
492 # No POD on purpose ...
493 # Does some common logic for swap_language() & init_special_date_arrays().
494 # Requires knowledge of the internals to Date::Manip::Lang::<language>
495 # in order to work.
496 # This method should avoid referencing any global variables!
497 # Returns: undef or the references to the 5 arrays!
498 # I would have broken it up ino multiple functions if not for the wide test!
499  
500 sub _swap_manip_language_common
501 0 ▶{
Subroutine _swap_manip_language_common: not called CC=31 SCAR=69.0
502 0 DBUG_ENTER_FUNC ( @_ );
503 0 my $lang_ref = shift;
504 0 my $warn_ok = shift;
505 0 ▶ my $allow_wide = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
506  
507 0 my $base = "Date::Manip";
508 0 my $lang = $lang_ref->{Language};
509 0 my $module = $lang_ref->{Module};
510  
511 # Check if the requested language module exists ...
512 {
513 0 local $SIG{__DIE__} = "";
514 0 my $sts = eval "require ${module}";
515 0 ▶ unless ( $sts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sts) 0 0 0
516 0 _warn_msg ( $warn_ok, "${base} doesn't recognize '${lang}' as valid!" );
517 0 return ( DBUG_RETURN ( undef, undef, undef, undef, undef, undef, undef, undef ) );
518 }
519 }
520  
521 # Get the proper name of this language fom the module.
522 0 $lang_ref->{Language} = $lang = eval "\$${module}::LangName";
523  
524 # Get the language data from the module.
525 0 my $langData = eval "\$${module}::Language"; # A hash reference with the data!
526  
527 # The 3 return values used by swap_language () ...
528 0 my (%months, %days, %issues);
529  
530 # The 5 return values used by init_special_date_arrays()
531 0 my ( @MoY, @MoYs, @Dsuf, @DoW, @DoWs);
532  
533 0 my $wide = 0;
534 0 my $has_period = 0;
535 0 foreach my $month_idx (1..12) {
536 0 foreach my $name ( @{$langData->{month_name}->[$month_idx-1]} ) {
537 0 my ($w, $k, $pi, $pe, $alt) = _fix_key ( $name );
538 0 ▶ $wide = 1 if ($w);
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
539 0 ▶ next if ( $pe && exists $months{$alt} && $months{$alt} == $month_idx );
Branch: 1 branch
BranchTrueFalseTotal
if $pe and exists $months{$alt} and $months{$alt} == $month_idx 0 0 0
Condition0%0/6
$pe and exists $months{$alt} and $months{$alt} == $month_idx
!ll&&!rl&&r
000
$pe and exists $months{$alt}
!ll&&!rl&&r
000
MC/DC0%0/3
$pe and exists $months{$alt} and $months{$alt} == $month_idx
$pe exists $months{$alt} $months{$alt} == $month_idx
Truth table0%0/4
A and B and C
A= $peB= exists $months{$alt}C= $months{$alt} == $month_idx
ABCresult
0XX0
10X0
1100
1111
540 0 ▶ $has_period = 1 if ( $pi || $pe );
Branch: 1 branch
BranchTrueFalseTotal
if $pi or $pe 0 0 0
Condition0%0/3
$pi or $pe
l!l&&r!l&&!r
000
MC/DC0%0/2
$pi or $pe
$pi $pe
Truth table0%0/3
A or B
A= $piB= $pe
ABresult
1X1
011
000
541 0 $months{$k} = $month_idx;
542 }
543 0 foreach my $abb ( @{$langData->{month_abb}->[$month_idx-1]} ) {
544 0 my ($w, $k, $pi, $pe, $alt) = _fix_key ( $abb );
545 0 ▶ $wide = 1 if ($w);
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
546 0 ▶ next if ( $pe && exists $months{$alt} && $months{$alt} == $month_idx );
Branch: 1 branch
BranchTrueFalseTotal
if $pe and exists $months{$alt} and $months{$alt} == $month_idx 0 0 0
Condition0%0/6
$pe and exists $months{$alt} and $months{$alt} == $month_idx
!ll&&!rl&&r
000
$pe and exists $months{$alt}
!ll&&!rl&&r
000
MC/DC0%0/3
$pe and exists $months{$alt} and $months{$alt} == $month_idx
$pe exists $months{$alt} $months{$alt} == $month_idx
Truth table0%0/4
A and B and C
A= $peB= exists $months{$alt}C= $months{$alt} == $month_idx
ABCresult
0XX0
10X0
1100
1111
547 0 ▶ $has_period = 1 if ( $pi || $pe );
Branch: 1 branch
BranchTrueFalseTotal
if $pi or $pe 0 0 0
Condition0%0/3
$pi or $pe
l!l&&r!l&&!r
000
MC/DC0%0/2
$pi or $pe
$pi $pe
Truth table0%0/3
A or B
A= $piB= $pe
ABresult
1X1
011
000
548 0 $months{$k} = $month_idx;
549 }
550  
551 0 my $first_name = $langData->{month_name}->[$month_idx-1]->[0];
552 0 my $first_abb = $langData->{month_abb}->[$month_idx-1]->[0];
553 0 push ( @MoY, (_fix_key ($first_name, 1))[1] );
554 0 push ( @MoYs, (_fix_key ($first_abb, 1))[1] );
555 }
556 0 $issues{month_period} = $has_period;
557  
558 0 $has_period = 0;
559 0 foreach my $day_idx (1..31) {
560 0 foreach my $day ( @{$langData->{nth}->[$day_idx-1]} ) {
561 0 my ($w, $k, $pi, $pe, $alt) = _fix_key ( $day );
562 0 ▶ $wide = 1 if ($w);
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
563 0 ▶ next if ( $pe && exists $days{$alt} && $days{$alt} == $day_idx );
Branch: 1 branch
BranchTrueFalseTotal
if $pe and exists $days{$alt} and $days{$alt} == $day_idx 0 0 0
Condition0%0/6
$pe and exists $days{$alt} and $days{$alt} == $day_idx
!ll&&!rl&&r
000
$pe and exists $days{$alt}
!ll&&!rl&&r
000
MC/DC0%0/3
$pe and exists $days{$alt} and $days{$alt} == $day_idx
$pe exists $days{$alt} $days{$alt} == $day_idx
Truth table0%0/4
A and B and C
A= $peB= exists $days{$alt}C= $days{$alt} == $day_idx
ABCresult
0XX0
10X0
1100
1111
564 0 ▶ $has_period = 1 if ( $pi || $pe );
Branch: 1 branch
BranchTrueFalseTotal
if $pi or $pe 0 0 0
Condition0%0/3
$pi or $pe
l!l&&r!l&&!r
000
MC/DC0%0/2
$pi or $pe
$pi $pe
Truth table0%0/3
A or B
A= $piB= $pe
ABresult
1X1
011
000
565 0 $days{$k} = $day_idx;
566 }
567  
568 0 my $first = $langData->{nth}->[$day_idx-1]->[0];
569 0 push ( @Dsuf, (_fix_key ($first, 1))[1] );
570 }
571 0 $issues{dsuf_period} = $has_period;
572  
573 # Need Sunday to Saturday to be consistent with localime() & Date::Language.
574 # But this array is Monday to Sunday!
575 # So take advantage of -1 being last element in array to fix!
576 0 $has_period = 0;
577 0 foreach my $wd_idx (1..7) {
578 0 my $wd = $langData->{day_name}->[$wd_idx - 2]->[0];
579 0 my ($w, $k, $pi, $pe, $alt) = _fix_key ( $wd, 1 );
580 0 ▶ $wide = 1 if ($w);
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
581 0 push (@DoW, $k);
582  
583 0 $wd = $langData->{day_abb}->[$wd_idx - 2]->[0];
584 0 ($w, $k, $pi, $pe, $alt) = _fix_key ( $wd, 1 );
585 0 ▶ $wide = 1 if ($w);
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
586 0 push (@DoWs, $k);
587 }
588 0 $issues{dow_period} = $has_period;
589  
590 0 $lang_ref->{Wide} = $wide;
591  
592 0 ▶ if ( $wide && ! $allow_wide ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wide and not $allow_wide) 0 0 0
Condition0%0/3
$wide and not $allow_wide
!ll&&!rl&&r
000
MC/DC0%0/2
$wide and not $allow_wide
$wide not $allow_wide
Truth table0%0/3
A and not(B)
A= $wideB= not $allow_wide
ABresult
0X0
100
111
593 0 _warn_msg ( $warn_ok, "'${lang}' uses Wide Chars. It's not currently enabled!" );
594 0 return ( DBUG_RETURN ( undef, undef, undef, undef, undef, undef, undef, undef ) );
595 }
596  
597 0 DBUG_RETURN ( \%months, \%days, \%issues, \@MoY, \@MoYs, \@Dsuf, \@DoW, \@DoWs);
598 }
599  
600 # ==============================================================
601 # So uc() & lc() works against all language values ...
602 sub _fix_key
603 0 ▶{
Subroutine _fix_key: not called CC=11 SCAR=48.8
604 0 my $value = shift;
605 0 ▶ my $keep_case = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
606  
607 0 ▶ my $wide = ( $value =~ m/[^\x00-\xff]/ ) ? 1 : 0; # Before ...
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /[^\x00-\xff]/ ? : 0 0 0
608  
609 0 ▶ unless ( $wide ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wide) 0 0 0
610 0 utf8::encode ($value);
611 0 utf8::decode ($value);
612  
613 # Now verify if any of the following makes it wide ...
614 0 ▶ if ( $value =~ m/[^\x00-\xff]/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /[^\x00-\xff]/ or lc($value) =~ /[^\x00-\xff]/ or uc($value) =~ /[^\x00-\xff]/) 0 0 0
Condition0%0/6
$value =~ /[^\x00-\xff]/ or lc($value) =~ /[^\x00-\xff]/ or uc($value) =~ /[^\x00-\xff]/
l!l&&r!l&&!r
000
$value =~ /[^\x00-\xff]/ or lc($value) =~ /[^\x00-\xff]/
l!l&&r!l&&!r
000
MC/DC0%0/3
$value =~ /[^\x00-\xff]/ or lc($value) =~ /[^\x00-\xff]/ or uc($value) =~ /[^\x00-\xff]/
$value =~ /[^\x00-\xff]/ lc($value) =~ /[^\x00-\xff]/ uc($value) =~ /[^\x00-\xff]/
Truth table0%0/4
A or B or C
A= $value =~ /[^\x00-\xff]/B= lc($value) =~ /[^\x00-\xff]/C= uc($value) =~ /[^\x00-\xff]/
ABCresult
1XX1
01X1
0011
0000
615 lc ($value) =~ m/[^\x00-\xff]/ ||
616 uc ($value) =~ m/[^\x00-\xff]/ ) {
617 0 $wide = 1;
618 }
619 }
620  
621 0 ▶ $value = lc ($value) unless ( $keep_case );
Branch: 1 branch
BranchTrueFalseTotal
unless $keep_case 0 0 0
622 0 my $alt = $value;
623  
624 0 my ($has_internal_period, $has_ending_period) = (0, 0);
625 0 ▶ if ( $value =~ m/([.]?)[^.]*(.)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([.]?)[^.]*(.)$/) 0 0 0
626 0 ▶ $has_internal_period = 1 if ($1 eq '.');
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "." 0 0 0
627 0 ▶ if ($2 eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq ".") 0 0 0
628 0 $has_ending_period = 1;
629 0 $alt =~ s/[.]$//;
630 }
631 }
632  
633 0 return ($wide, lc $value, $has_internal_period, $has_ending_period, $alt);
634 }
635  
636 # ==============================================================
637 # It's a mess since Date::Manip allows for aliases.
638  
639 sub _select_language
640 224 ▶{
Subroutine _select_language: called CC=12 SCAR=26.3
641 224 DBUG_ENTER_FUNC ( @_ );
642 224 my $lang = shift;
643 224 my $warn_ok = shift;
644 224 my $allow_wide = shift;
645  
646 224 my $k = lc ($lang);
647 224 my $manip_ref = $date_manip_installed_languages{$k};
648 224 my $lang_ref = $date_language_installed_languages{$k};
649  
650 224 ▶ if ( $manip_ref && ! $lang_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($manip_ref and not $lang_ref) 0 224 224
Condition33%1/3
$manip_ref and not $lang_ref
!ll&&!rl&&r
22400
MC/DC0%0/2
$manip_ref and not $lang_ref
$manip_ref not $lang_ref
Truth table33%1/3
A and not(B)
A= $manip_refB= not $lang_ref
ABresult
0X0
100
111
651 0 $k = lc ($manip_ref->{Language});
652 0 $lang_ref = $date_language_installed_languages{$k};
653 }
654  
655 224 ▶ unless ( $lang_ref || $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lang_ref or $manip_ref) 2 222 224
Condition66%2/3
$lang_ref or $manip_ref
l!l&&r!l&&!r
22202
MC/DC50%1/2
$lang_ref or $manip_ref
$lang_ref $manip_ref
Truth table66%2/3
A or B
A= $lang_refB= $manip_ref
ABresult
1X1
011
000
656 2 _warn_msg ( $warn_ok, "Language '$lang' does not exist! So can't swap to it!" );
657 2 return DBUG_RETURN ( undef, undef );
658 }
659  
660 222 ▶ unless ( $allow_wide ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_wide) 183 39 222
661 183 ▶ $manip_ref = undef if ( $manip_ref && $manip_ref->{Wide} );
Branch: 1 branch
BranchTrueFalseTotal
if $manip_ref and $manip_ref->{"Wide"} 0 183 183
Condition33%1/3
$manip_ref and $manip_ref->{"Wide"}
!ll&&!rl&&r
18300
MC/DC0%0/2
$manip_ref and $manip_ref->{"Wide"}
$manip_ref $manip_ref->{"Wide"}
Truth table33%1/3
A and B
A= $manip_refB= $manip_ref->{"Wide"}
ABresult
0X0
100
111
662 183 ▶ $lang_ref = undef if ( $lang_ref && $lang_ref->{Wide} );
Branch: 1 branch
BranchTrueFalseTotal
if $lang_ref and $lang_ref->{"Wide"} 1 182 183
Condition66%2/3
$lang_ref and $lang_ref->{"Wide"}
!ll&&!rl&&r
01821
MC/DC50%1/2
$lang_ref and $lang_ref->{"Wide"}
$lang_ref $lang_ref->{"Wide"}
Truth table66%2/3
A and B
A= $lang_refB= $lang_ref->{"Wide"}
ABresult
0X0
100
111
663  
664 183 ▶ unless ( $lang_ref || $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lang_ref or $manip_ref) 1 182 183
Condition66%2/3
$lang_ref or $manip_ref
l!l&&r!l&&!r
18201
MC/DC50%1/2
$lang_ref or $manip_ref
$lang_ref $manip_ref
Truth table66%2/3
A or B
A= $lang_refB= $manip_ref
ABresult
1X1
011
000
665 1 _warn_msg ( $warn_ok, "Language '$lang' uses Wide Chars. It's not currently enabled!" );
666 1 return DBUG_RETURN ( undef, undef );
667 }
668 }
669  
670 221 DBUG_RETURN ( $manip_ref, $lang_ref );
671 }
672  
673 # ==============================================================
674  
675 =item $lang = swap_language ( $language[, $give_warning[, $wide]] );
676  
677 This method allows you to change the I<$language> used when this module parses
678 a date string if you have modules L<Date::Language> and/or L<Date::Manip>
679 installed. But if neither are installed, only dates in B<English> are
680 supported. If a language is defined in both places the results are merged.
681  
682 It always returns the active language. So if I<$language> is B<undef> or
683 invalid, it will return the current language from before the call. But if the
684 language was successfully changed, it will return the new I<$language> instead.
685  
686 Should the change fail and I<$give_warning> is set to a non-zero value, it will
687 write a warning to your screen telling you why it failed.
688  
689 So assuming one of the language modules are installed, it asks it for the list
690 of months in the requested language. And once that list is retrieved only
691 months in that language are supported when parsing a date string.
692  
693 Languages like 'Greek' that rely on I<Wide Chars> require the I<$wide> flag set
694 to true. Otherwise that language is disabled. Using the I<use_ut8> option
695 when creating the Advanced::Config object causes the I<$wide> flag to be set to
696 B<1>.
697  
698 =cut
699  
700 # NOTE: Sets the following global variables for use by parse_date() ...
701 # %last_language_edit_flags
702 # %Months
703 # %Days
704  
705 sub swap_language
706 2702 ▶{
Subroutine swap_language: called CC=31 SCAR=39.4
Pod documented
707 2702 DBUG_ENTER_FUNC ( @_ );
708 2702 my $lang = shift;
709 2702 my $warn_ok = shift;
710 2702 ▶ my $allow_wide = shift || 0;
Condition100%2/2
shift() || 0
l!l
1872830
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
711  
712 2702 ▶ if ( (! defined $lang) || lc($lang) eq lc($last_language_edit_flags{language}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $lang or lc $lang eq lc $last_language_edit_flags{"language"}) 2639 63 2702
Condition66%2/3
not defined $lang or lc $lang eq lc $last_language_edit_flags{"language"}
l!l&&r!l&&!r
0263963
MC/DC50%1/2
not defined $lang or lc $lang eq lc $last_language_edit_flags{"language"}
not defined $lang lc $lang eq lc $last_language_edit_flags{"language"}
Truth table66%2/3
not(A) or B
A= not defined $langB= lc $lang eq lc $last_language_edit_flags{"language"}
ABresult
1X1
011
000
713 2639 return DBUG_RETURN ( $last_language_edit_flags{language} );
714 }
715  
716 63 my ($manip_ref, $lang_ref) = _select_language ($lang, $warn_ok, $allow_wide);
717  
718 63 ▶ unless ( $lang_ref || $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lang_ref or $manip_ref) 3 60 63
Condition66%2/3
$lang_ref or $manip_ref
l!l&&r!l&&!r
6003
MC/DC50%1/2
$lang_ref or $manip_ref
$lang_ref $manip_ref
Truth table66%2/3
A or B
A= $lang_refB= $manip_ref
ABresult
1X1
011
000
719 3 return DBUG_RETURN ( $last_language_edit_flags{language} );
720 }
721  
722 60 my ($month_ref, $day_ref, $issue1_ref);
723 60 ▶ if ( $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($manip_ref) 0 60 60
724 0 my $old = $manip_ref->{Language};
725 0 ($month_ref, $day_ref, $issue1_ref) =
726 _swap_manip_language_common ($manip_ref, $warn_ok, $allow_wide );
727 0 $lang = $manip_ref->{Language};
728  
729 0 ▶ if ( $old ne $lang && ! $lang_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old ne $lang and not $lang_ref) 0 0 0
Condition0%0/3
$old ne $lang and not $lang_ref
!ll&&!rl&&r
000
MC/DC0%0/2
$old ne $lang and not $lang_ref
$old ne $lang not $lang_ref
Truth table0%0/3
A and not(B)
A= $old ne $langB= not $lang_ref
ABresult
0X0
100
111
730 0 $lang_ref = $date_language_installed_languages{lc($lang)};
731 0 ▶ $lang_ref = undef if ($lang_ref && $lang_ref->{Wide} && ! $allow_wide);
Branch: 1 branch
BranchTrueFalseTotal
if $lang_ref and $lang_ref->{"Wide"} and not $allow_wide 0 0 0
Condition0%0/6
$lang_ref and $lang_ref->{"Wide"} and not $allow_wide
!ll&&!rl&&r
000
$lang_ref and $lang_ref->{"Wide"}
!ll&&!rl&&r
000
MC/DC0%0/3
$lang_ref and $lang_ref->{"Wide"} and not $allow_wide
$lang_ref $lang_ref->{"Wide"} not $allow_wide
Truth table0%0/4
A and B and not(C)
A= $lang_refB= $lang_ref->{"Wide"}C= not $allow_wide
ABCresult
0XX0
10X0
1100
1111
732 }
733 }
734  
735 60 my ($MoY_ref, $MoYs_ref, $Dsuf_ref, $issue2_ref);
736 60 ▶ if ( $lang_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang_ref) 60 0 60
737 60 my ($unused_DoW_ref, $unused_DoWs_ref);
738 60 ($MoY_ref, $MoYs_ref, $Dsuf_ref, $unused_DoW_ref, $unused_DoWs_ref, $issue2_ref) =
739 _swap_lang_common ( $lang_ref, $warn_ok, $allow_wide );
740 60 $lang = $lang_ref->{Language};
741 }
742  
743 60 ▶ unless ( $MoY_ref || $month_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($MoY_ref or $month_ref) 1 59 60
Condition66%2/3
$MoY_ref or $month_ref
l!l&&r!l&&!r
5901
MC/DC50%1/2
$MoY_ref or $month_ref
$MoY_ref $month_ref
Truth table66%2/3
A or B
A= $MoY_refB= $month_ref
ABresult
1X1
011
000
744 1 return DBUG_RETURN ( $last_language_edit_flags{language} );
745 }
746  
747 DBUG_PRINT ("SWAP", "Swapping from '%s' to '%s'.",
748 59 $last_language_edit_flags{language}, $lang);
749  
750 # ---------------------------------------------------------
751 59 foreach my $k ( keys %last_language_edit_flags ) {
752 236 ▶ $last_language_edit_flags{$k} = $issue1_ref->{$k} || $issue2_ref->{$k} || 0;
Condition80%4/5
$issue1_ref->{$k} || $issue2_ref->{$k} || 0
l!l
2234
$issue1_ref->{$k} or $issue2_ref->{$k}
l!l&&r!l&&!r
02234
MC/DC50%1/2
$issue1_ref->{$k} || $issue2_ref->{$k} || 0
$issue1_ref->{$k} $issue2_ref->{$k}
Truth table66%2/3
A or B
A= $issue1_ref->{$k}B= $issue2_ref->{$k}
ABresult
1X1
011
000
753 }
754 59 $last_language_edit_flags{language} = $lang;
755  
756 # ---------------------------------------------------------
757 # Bug Alert: For some languges the following isn't true!
758 # lc(MoY) != lc(uc(lc(MoY)))
759 # So we have multiple lower case letters mapping to the
760 # same upper case letters#.
761 # ---------------------------------------------------------
762 # This happens for 3 languages for Date::Language.
763 # Chinese_GB, Greek & Russian_cp1251
764 # And one language for Date::Manip
765 # Turkish
766 # ---------------------------------------------------------
767  
768 59 my %empty;
769 59 %Months = %Days = %empty;
770  
771 # ---------------------------------------------------------
772 # Put in the common numeric values into the hashes ...
773 59 my $cnt;
774 59 foreach $cnt ( 1..12 ) {
775 708 $Months{$cnt} = $cnt;
776 }
777  
778 59 foreach my $day ( 1..31 ) {
779 1829 $Days{$day} = $day;
780 }
781  
782 # ---------------------------------------------------------
783 # Merge in the Date::Manip::Lang::<language> values ...
784  
785 59 foreach my $mon ( keys %{$month_ref} ) {
786 0 $Months{$mon} = $month_ref->{$mon};
787 0 $Months{lc (uc (lc ($mon)))} = $Months{$mon}; # Bug fix, but usually same.
788 }
789  
790 59 foreach my $day ( keys %{$day_ref} ) {
791 0 $Days{$day} = $day_ref->{$day};
792 0 $Days{lc (uc (lc ($day)))} = $Days{$day}; # Bug fix, but usually same.
793 }
794  
795 # ---------------------------------------------------------
796 # Merge in the Date::Language::<language> values ...
797  
798 59 $cnt = 1;
799 59 foreach my $mon ( @{$MoY_ref} ) {
800 708 $Months{lc ($mon)} = $cnt;
801 708 $Months{lc (uc (lc ($mon)))} = $cnt; # Bug fix, but usually same.
802 708 ++$cnt;
803 }
804  
805 59 $cnt = 1;
806 59 foreach my $mon ( @{$MoYs_ref} ) {
807 708 $Months{lc ($mon)} = $cnt;
808 708 $Months{lc (uc (lc ($mon)))} = $cnt; # Bug fix, but usually same.
809 708 ++$cnt;
810 }
811  
812 59 foreach my $day ( 1..31 ) {
813 1829 ▶ if ( $Dsuf_ref && defined $Dsuf_ref->[$day] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Dsuf_ref and defined $Dsuf_ref->[$day]) 1428 401 1829
Condition66%2/3
$Dsuf_ref and defined $Dsuf_ref->[$day]
!ll&&!rl&&r
04011428
MC/DC50%1/2
$Dsuf_ref and defined $Dsuf_ref->[$day]
$Dsuf_ref defined $Dsuf_ref->[$day]
Truth table66%2/3
A and B
A= $Dsuf_refB= defined $Dsuf_ref->[$day]
ABresult
0X0
100
111
814 1428 my $key = $Dsuf_ref->[$day];
815 1428 $Days{lc ($key)} = $day;
816 1428 $Days{lc (uc (lc ($key)))} = $day; # Bug fix, but usually same.
817 }
818 }
819  
820 # ---------------------------------------------------------
821 # Report the results ...
822  
823 DBUG_PRINT ( "LANGUAGE", "%s\n%s\n%s",
824 7820 ▶ join (", ", sort { $Months{$a} <=> $Months{$b} || $a cmp $b } keys %Months),
Condition66%2/3
$Months{$a} <=> $Months{$b} || $a cmp $b
l!l&&r!l&&!r
610817120
MC/DC0%0/2
$Months{$a} <=> $Months{$b} || $a cmp $b
$Months{$a} <=> $Months{$b} $a cmp $b
Truth table66%2/3
A || B
A= $Months{$a} <=> $Months{$b}B= $a cmp $b
ABresult
1X1
011
000
825 59 ▶ join (", ", sort { my ($x,$y) = ($a,$b); $x=~s/\D+//g; $y=~s/\D+//g; $x=0 if ($x eq ""); $y=0 if ($y eq ""); ($x<=>$y || $a cmp $b) } keys %Days),
Branch: 2 branches
BranchTrueFalseTotal
if $x eq "" 0 14715 14715
if $y eq "" 0 14715 14715
Condition66%2/3
$x <=> $y || $a cmp $b
l!l&&r!l&&!r
1334313720
MC/DC0%0/2
$x <=> $y || $a cmp $b
$x <=> $y $a cmp $b
Truth table66%2/3
A || B
A= $x <=> $yB= $a cmp $b
ABresult
1X1
011
000
826 join (", ", %last_language_edit_flags) );
827  
828 59 DBUG_RETURN ( $lang );
829 }
830  
831  
832 # ==============================================================
833  
834 =item $date = parse_date ( $date_str, $order[, $allow_dl[, $enable_2_digit_years]] );
835  
836 Passed a date in some unknown format, it does it's best to parse it and return
837 the date in S<YYYY-MM-DD> format if it's a valid date. It returns B<undef> if
838 it can't find a valid date within I<$date_str>.
839  
840 The date can be surrounded by other information in the string that will be
841 ignored. So it will strip out just the date info in something like:
842  
843 =over 4
844  
845 Tues B<January 3rd, 2017> at 6:00 PM.
846  
847 =back
848  
849 There are too many valid date formats to list them all, especially when other
850 languages are added to the mix. But if you have one it doesn't support, open
851 a CPAN ticket and I'll see if I can quickly add it.
852  
853 I<$order> tells the order to use for interpreting dates that are all digits.
854 It's forwarded to all internal calls to L<parse_6_digit_date> and
855 L<parse_8_digit_date>. So see those methods POD for more info on its meaning.
856  
857 I<$allow_dl> is non-zero and L<Date::Language> is installed use it's method
858 B<str2time ()> to attempt the conversion only if nothing else worked.
859  
860 If I<$enable_2_digit_years> is set to zero, it will not recognize any 2-digit
861 year date formats as valid. Set to a non-zero value to enable them.
862  
863 =cut
864  
865 # Check out Date::Parse for date examples to use to test this function out.
866  
867 sub lcx
868 8638 ▶{
Subroutine lcx: called CC=2 SCAR=6.9
Pod undocumented
869 8638 my $str = shift;
870  
871 8638 ▶ unless ( utf8::is_utf8 ($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::is_utf8($str)) 2606 6032 8638
872 2606 utf8::encode ($str);
873 2606 utf8::decode ($str);
874 }
875  
876 8638 return (lc ($str));
877 }
878  
879 sub _tst
880 0 ▶{
Subroutine _tst: not called CC=1 SCAR=6.9
881 0 my $s = shift;
882 0 my $nm = shift;
883 0 my $dm = shift;
884 0 DBUG_PRINT ("TST", "Matched Pattern (%s) Sep: %s Name: %s Dom: %s", join (",",@_), $s, $nm, $dm);
885 0 return (1);
886 }
887  
888 # DEPRECIATED VERSION ...
889 sub parse_date_old
890 0 ▶{
Subroutine parse_date_old: not called CC=71 SCAR=85.4
Pod undocumented
891 0 DBUG_ENTER_FUNC ( @_ );
892 0 my $in_date = shift; # A potential date in an unknown format ...
893 0 my $date_format_options = shift; # A comma separated list of ids ...
894 0 ▶ my $use_date_language_module = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
895 0 ▶ my $allow_2_digit_years = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
896  
897 # The Month name pattern, ... [a-zA-Z] doesn't work for other languages.
898 0 my $name = "[^-\$\\s\\d.,|\\[\\]\\\\/{}()]";
899  
900 # The Day of Month pattern ... (when not all digits are expected)
901 0 my $dom = "\\d{0,2}${name}*";
902  
903 # Remove the requesed character from the month pattern ...
904 0 ▶ $name =~ s/\\s//g if ( $last_language_edit_flags{month_spaces} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"month_spaces"} 0 0 0
905 0 ▶ $name =~ s/[.]//g if ( $last_language_edit_flags{month_period} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"month_period"} 0 0 0
906 0 ▶ $name =~ s/-//g if ( $last_language_edit_flags{month_hyphin} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"month_hyphin"} 0 0 0
907  
908 0 $name .= '+'; # Terminate the name pattern.
909  
910 # Remove the requesed character from the day of month pattern ...
911 0 ▶ $dom =~ s/\\s//g if ( $last_language_edit_flags{dsuf_spaces} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"dsuf_spaces"} 0 0 0
912 0 ▶ $dom =~ s/[.]//g if ( $last_language_edit_flags{dsuf_period} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"dsuf_period"} 0 0 0
913 0 ▶ $dom =~ s/-//g if ( $last_language_edit_flags{dsuf_hyphin} );
Branch: 1 branch
BranchTrueFalseTotal
if $last_language_edit_flags{"dsuf_hyphin"} 0 0 0
914  
915 0 my ( $year, $month, $day );
916 0 my ( $s1, $s2 ) = ( "", "" );
917 0 my $fmt = "n/a";
918  
919 # The 7 separators to cycle through to parse things correctly ...
920 0 my @seps = ( "-", "/", "[.]", ",", "\\s+", '\\\\', ":" );
921  
922 # -------------------------------------------------------
923 # Let's start with the 4-digit year formats ...
924 # -------------------------------------------------------
925 0 foreach my $sep ( @seps ) {
926 0 ▶ if ( $in_date =~ m/(^|\D)(\d{4})(${sep})(\d{1,2})(${sep})(\d{1,2})(\D|$)/ ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)(\d{4})($sep)(\d{1,2})($sep)(\d{1,2})(\D|$)/) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{1,2})($sep)(\d{1,2})($sep)(\d{4})(\D|$)/) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)}) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)(\d{1,2})(\D|$)/ and exists $Months{lcx($4)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($2)}) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($6)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)} and exists $Days{lcx($4)}) { } 0 0 0
927 0 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
928 0 $fmt = "YYYY${s1}MM${s2}DD"; # ISO format
929  
930 } elsif ( $in_date =~ m/(^|\D)(\d{1,2})(${sep})(\d{1,2})(${sep})(\d{4})(\D|$)/ ) {
931 0 ( $month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
932 0 ( $year, $month, $day ) = parse_8_digit_date ( sprintf ("%02d%02d%04d", $month, $day, $year),
933 $date_format_options, 1 );
934 0 $fmt = "MM${s1}DD${s2}YYYY"; # European or American format (ambiguous?)
935  
936 # ------------------------------------------------------------------------------------------
937 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{1,2})(${sep})(${name})[.]?(${sep})(\d{4})(\D|$)/ &&
Condition0%0/3
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)}
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{4})(\D|$)/ exists $Months{lcx($4)}
Truth table0%0/3
A and B
A= $in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{4})(\D|$)/B= exists $Months{lcx($4)}
ABresult
0X0
100
111
938 exists $Months{lcx($4)} ) {
939 0 ( $day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 );
940 0 $fmt = "DD${s1}Month${s2}YYYY";
941  
942 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{4})(${sep})(${name})[.]?(${sep})(\d{1,2})(\D|$)/ &&
Condition0%0/3
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)(\d{1,2})(\D|$)/ and exists $Months{lcx($4)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)(\d{1,2})(\D|$)/ and exists $Months{lcx($4)}
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)(\d{1,2})(\D|$)/ exists $Months{lcx($4)}
Truth table0%0/3
A and B
A= $in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)(\d{1,2})(\D|$)/B= exists $Months{lcx($4)}
ABresult
0X0
100
111
943 exists $Months{lcx($4)} ) {
944 0 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
945 0 $fmt = "YYYY${s1}Month${s2}DD";
946  
947 ▶ } elsif ( $in_date =~ m/(^|\s)(${name})(${sep})(\d{1,2})(${sep})(\d{4})(\D|$)/ &&
Condition0%0/3
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)}
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{4})(\D|$)/ exists $Months{lcx($2)}
Truth table0%0/3
A and B
A= $in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{4})(\D|$)/B= exists $Months{lcx($2)}
ABresult
0X0
100
111
948 exists $Months{lcx($2)} ) {
949 0 ( $month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
950 0 $fmt = "Month${s1}DD${s2}YYYY";
951  
952 # ------------------------------------------------------------------------------------------
953 ▶ } elsif ( $in_date =~ m/(^|\s)(${dom})(${sep})(${name})[.]?(${sep})(\d{4})(\D|$)/ &&
Condition0%0/6
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($2)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)}
!ll&&!rl&&r
000
MC/DC0%0/3
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($2)}
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/ exists $Months{lcx($4)} exists $Days{lcx($2)}
Truth table0%0/4
A and B and C
A= $in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{4})(\D|$)/B= exists $Months{lcx($4)}C= exists $Days{lcx($2)}
ABCresult
0XX0
10X0
1100
1111
954 exists $Months{lcx($4)} &&
955 exists $Days{lcx($2)} ) {
956 0 ( $day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 );
957 0 $fmt = "Day${s1}Month${s2}YYYY"; # European format
958  
959 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{4})(${sep})(${name})[.]?(${sep})(${dom})(\s|$)/ &&
Condition0%0/6
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($6)}
!ll&&!rl&&r
000
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/ and exists $Months{lcx($4)}
!ll&&!rl&&r
000
MC/DC0%0/3
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/ and exists $Months{lcx($4)} and exists $Days{lcx($6)}
$in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/ exists $Months{lcx($4)} exists $Days{lcx($6)}
Truth table0%0/4
A and B and C
A= $in_date =~ /(^|\D)(\d{4})($sep)($name)[.]?($sep)($dom)(\s|$)/B= exists $Months{lcx($4)}C= exists $Days{lcx($6)}
ABCresult
0XX0
10X0
1100
1111
960 exists $Months{lcx($4)} &&
961 exists $Days{lcx($6)} ) {
962 0 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
963 0 $fmt = "YYYY${s1}Month${s2}Day"; # ISO format
964  
965 ▶ } elsif ( $in_date =~ m/(^|\s)(${name})(${sep})(${dom})(${sep})(\d{4})(\D|$)/ &&
Condition0%0/6
$in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)} and exists $Days{lcx($4)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)}
!ll&&!rl&&r
000
MC/DC0%0/3
$in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/ and exists $Months{lcx($2)} and exists $Days{lcx($4)}
$in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/ exists $Months{lcx($2)} exists $Days{lcx($4)}
Truth table0%0/4
A and B and C
A= $in_date =~ /(^|\s)($name)($sep)($dom)($sep)(\d{4})(\D|$)/B= exists $Months{lcx($2)}C= exists $Days{lcx($4)}
ABCresult
0XX0
10X0
1100
1111
966 exists $Months{lcx($2)} &&
967 exists $Days{lcx($4)} ) {
968 0 ( $month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
969 0 $fmt = "Month${s1}Day${s2}YYYY"; # American format
970 }
971  
972 0 ▶ last if ( defined $year );
Branch: 1 branch
BranchTrueFalseTotal
if defined $year 0 0 0
973 }
974  
975 0 ▶ if ( defined $year ) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $year) { } 0 0 0
elsif ($in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{4})(\D|$)/ and exists $Months{lcx($1)}) { } 0 0 0
elsif ($in_date =~ /($name)[.]?\s+($dom)[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/ and exists $Months{lcx($1)}) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{8})(\D|$)/) { } 0 0 0
elsif ($allow_2_digit_years) { } 0 0 0
976 ; # No more formatting tests needed ...
977  
978 # "Month Day, YYYY" or "Month Day YYYY"
979 ▶ } elsif ( $in_date =~ m/(${name})[.\s]\s*(${dom})[,\s]\s*(\d{4})(\D|$)/ &&
Condition0%0/3
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{4})(\D|$)/ and exists $Months{lcx($1)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{4})(\D|$)/ and exists $Months{lcx($1)}
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{4})(\D|$)/ exists $Months{lcx($1)}
Truth table0%0/3
A and B
A= $in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{4})(\D|$)/B= exists $Months{lcx($1)}
ABresult
0X0
100
111
980 exists $Months{lcx($1)} ) {
981 0 ( $month, $day, $year ) = ( $1, $2, $3 );
982 0 $fmt = "Month Day, YYYY";
983  
984 # "Month Day, HH:MM:SS YYYY" or "Month Day HH:MM:SS YYYY"
985 # Added because: "$dt = localtime(time())" generates this format.
986 ▶ } elsif ( $in_date =~ m/(${name})[.]?\s+(${dom})[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/ &&
Condition0%0/3
$in_date =~ /($name)[.]?\s+($dom)[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/ and exists $Months{lcx($1)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /($name)[.]?\s+($dom)[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/ and exists $Months{lcx($1)}
$in_date =~ /($name)[.]?\s+($dom)[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/ exists $Months{lcx($1)}
Truth table0%0/3
A and B
A= $in_date =~ /($name)[.]?\s+($dom)[,\s]\s*(\d{1,2}:\d{1,2}(:\d{1,2})?)\s+(\d{4})(\D|$)/B= exists $Months{lcx($1)}
ABresult
0X0
100
111
987 exists $Months{lcx($1)} ) {
988 0 my $time;
989 0 ( $month, $day, $time, $year ) = ( $1, $2, $3, $5 );
990 0 $fmt = "Month Day HH:MM[:SS] YYYY";
991  
992 # As a string of 8 digits.
993 } elsif ( $in_date =~ m/(^|\D)(\d{8})(\D|$)/ ) {
994 0 ($year, $month, $day) = parse_8_digit_date ( $2, $date_format_options, 0 );
995 0 $fmt = "YYYYMMDD";
996  
997 # -------------------------------------------------------
998 # Finally, assume it's using a 2-digit year format ...
999 # Only if they are allowed ...
1000 # -------------------------------------------------------
1001 } elsif ( $allow_2_digit_years ) {
1002 0 foreach my $sep ( @seps ) {
1003 0 ▶ next if ( $sep eq ":" ); # Skip, if used it looks like a time of day ...
Branch: 1 branch
BranchTrueFalseTotal
if $sep eq ":" 0 0 0
1004  
1005 0 ▶ if ( $in_date =~ m/(^|[^:\d])(\d{1,2})(${sep})(\d{1,2})(${sep})(\d{1,2})([^:\d]|$)/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|[^:\d])(\d{1,2})($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($4)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($2)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($2)} and exists $Days{lcx($4)}) { } 0 0 0
elsif ($in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($2)}) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($6)}) { } 0 0 0
1006 0 ($s1, $s2) = ($3, $5);
1007 0 my $yymmdd = sprintf ("%02d%02d%02d", $2, $4, $6);
1008 0 ($year, $month, $day) = parse_6_digit_date ( $yymmdd, $date_format_options );
1009 0 $fmt = "YY${s1}MM${s2}DD ???";
1010  
1011 # ------------------------------------------------------------------------------------------
1012 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{1,2})(${sep})(${name})[.]?(${sep})(\d{1,2})([^:\d]|$)/ &&
Condition0%0/3
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($4)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($4)}
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ exists $Months{lcx($4)}
Truth table0%0/3
A and B
A= $in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/B= exists $Months{lcx($4)}
ABresult
0X0
100
111
1013 exists $Months{lcx($4)} ) {
1014 0 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1015 0 my $yymmdd = sprintf ("%02d%02d%02d", $year, $Months{lcx($month)}, $day);
1016 0 my @order;
1017 0 foreach ( split (/\s*,\s*/, $date_format_options) ) {
1018 0 ▶ push (@order, $_) if ( $_ != 2 ); # If not American format ...
Branch: 1 branch
BranchTrueFalseTotal
if $_ != 2 0 0 0
1019 }
1020 0 ($year, $month, $day) = parse_6_digit_date ( $yymmdd, join(",", @order) );
1021 0 $fmt = "DD${s1}Month${s2}YY or YY${s1}Month${s2}DD";
1022  
1023 ▶ } elsif ( $in_date =~ m/(^|\s)(${name})(${sep})(\d{1,2})(${sep})(\d{1,2})([^:\d]|$)/ &&
Condition0%0/3
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($2)}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/ and exists $Months{lcx($2)}
$in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/ exists $Months{lcx($2)}
Truth table0%0/3
A and B
A= $in_date =~ /(^|\s)($name)($sep)(\d{1,2})($sep)(\d{1,2})([^:\d]|$)/B= exists $Months{lcx($2)}
ABresult
0X0
100
111
1024 exists $Months{lcx($2)} ) {
1025 0 ( $month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1026 0 $year = make_it_a_4_digit_year ( $year );
1027 0 $fmt = "Month${s1}DD${s2}YY";
1028  
1029 # ------------------------------------------------------------------------------------------
1030 ▶ } elsif ( $in_date =~ m/(^|\s)(${name})[.]?(${sep})(${dom})(${sep})(\d{1,2})([^:\d]|$)/ &&
Condition0%0/9
$in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($2)} and exists $Days{lcx($4)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($2)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6)
!ll&&!rl&&r
000
MC/DC0%0/4
$in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($2)} and exists $Days{lcx($4)}
$in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/ _tst($sep, $name, $dom, $2, $4, $6) exists $Months{lcx($2)} exists $Days{lcx($4)}
Truth table0%0/5
A and B and C and D
A= $in_date =~ /(^|\s)($name)[.]?($sep)($dom)($sep)(\d{1,2})([^:\d]|$)/B= _tst($sep, $name, $dom, $2, $4, $6)C= exists $Months{lcx($2)}D= exists $Days{lcx($4)}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1031 _tst( $sep, $name, $dom, $2, $4, $6 ) &&
1032 exists $Months{lcx($2)} &&
1033 exists $Days{lcx($4)} ) {
1034 0 ( $month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1035 0 $year = make_it_a_4_digit_year ( $year );
1036 0 $fmt = "Month${s1}Day${s2}YY"; # American format
1037  
1038 ▶ } elsif ( $in_date =~ m/(^|\s)(${dom})(${sep})(${name})[.]?(${sep})(\d{1,2})([^:\d]|$)/ &&
Condition0%0/9
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($2)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)}
!ll&&!rl&&r
000
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6)
!ll&&!rl&&r
000
MC/DC0%0/4
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($2)}
$in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/ _tst($sep, $name, $dom, $2, $4, $6) exists $Months{lcx($4)} exists $Days{lcx($2)}
Truth table0%0/5
A and B and C and D
A= $in_date =~ /(^|\s)($dom)($sep)($name)[.]?($sep)(\d{1,2})([^:\d]|$)/B= _tst($sep, $name, $dom, $2, $4, $6)C= exists $Months{lcx($4)}D= exists $Days{lcx($2)}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1039 _tst( $sep, $name, $dom, $2, $4, $6 ) &&
1040 exists $Months{lcx($4)} &&
1041 exists $Days{lcx($2)} ) {
1042 0 ( $day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1043 0 $year = make_it_a_4_digit_year ( $year );
1044 0 $fmt = "Day${s1}Month${s2}YY"; # European format
1045  
1046 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{1,2})(${sep})(${name})[.]?(${sep})(${dom})(\s|$)/ &&
Condition0%0/9
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($6)}
!ll&&!rl&&r
000
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)}
!ll&&!rl&&r
000
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ and _tst($sep, $name, $dom, $2, $4, $6)
!ll&&!rl&&r
000
MC/DC0%0/4
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ and _tst($sep, $name, $dom, $2, $4, $6) and exists $Months{lcx($4)} and exists $Days{lcx($6)}
$in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/ _tst($sep, $name, $dom, $2, $4, $6) exists $Months{lcx($4)} exists $Days{lcx($6)}
Truth table0%0/5
A and B and C and D
A= $in_date =~ /(^|\D)(\d{1,2})($sep)($name)[.]?($sep)($dom)(\s|$)/B= _tst($sep, $name, $dom, $2, $4, $6)C= exists $Months{lcx($4)}D= exists $Days{lcx($6)}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1047 _tst( $sep, $name, $dom, $2, $4, $6 ) &&
1048 exists $Months{lcx($4)} &&
1049 exists $Days{lcx($6)} ) {
1050 0 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1051 0 $year = make_it_a_4_digit_year ( $year );
1052 0 $fmt = "YY${s1}Month${s2}Day"; # ISO format
1053 }
1054  
1055 0 ▶ last if ( defined $year );
Branch: 1 branch
BranchTrueFalseTotal
if defined $year 0 0 0
1056 }
1057  
1058 0 ▶ if ( defined $year ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $year) { } 0 0 0
elsif ($in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/ and _tst('\\s', $name, $dom, $1, $2, $3) and exists $Months{lcx($1)}) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{6})(\D|$)/) { } 0 0 0
1059 ; # No more formatting tests needed ...
1060  
1061 # "Month Day, YY" or "Month Day YY"
1062 ▶ } elsif ( $in_date =~ m/(${name})[.\s]\s*(${dom})[,\s]\s*(\d{2})(\D|$)/ &&
Condition0%0/6
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/ and _tst("\\s", $name, $dom, $1, $2, $3) and exists $Months{lcx($1)}
!ll&&!rl&&r
000
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/ and _tst("\\s", $name, $dom, $1, $2, $3)
!ll&&!rl&&r
000
MC/DC0%0/3
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/ and _tst("\\s", $name, $dom, $1, $2, $3) and exists $Months{lcx($1)}
$in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/ _tst("\\s", $name, $dom, $1, $2, $3) exists $Months{lcx($1)}
Truth table0%0/4
A and B and C
A= $in_date =~ /($name)[.\s]\s*($dom)[,\s]\s*(\d{2})(\D|$)/B= _tst("\\s", $name, $dom, $1, $2, $3)C= exists $Months{lcx($1)}
ABCresult
0XX0
10X0
1100
1111
1063 _tst( "\\s", $name, $dom, $1, $2, $3 ) &&
1064 exists $Months{lcx($1)} ) {
1065 0 ( $month, $day ) = ( $1, $2 );
1066 0 $year = make_it_a_4_digit_year ( $3 );
1067 0 $fmt = "Month Day, YY";
1068  
1069 # As a string of 6 digits.
1070 } elsif ( $in_date =~ m/(^|\D)(\d{6})(\D|$)/ ) {
1071 0 ($year, $month, $day) = parse_6_digit_date ( $2, $date_format_options );
1072 0 $fmt = "YYMMDD";
1073 }
1074 } # End if its a 2-digit year ...
1075  
1076  
1077 # --------------------------------------------------------------------
1078 # If my parsing didn't work try using Date::Language if it's installed.
1079 # Keep after my checks so that things are consistent when this module
1080 # isn't installed. (No way to disable 2-digit year format here.)
1081 # --------------------------------------------------------------------
1082  
1083 0 ▶ if ( $use_date_language_module && ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_date_language_module and not defined $year) 0 0 0
Condition0%0/3
$use_date_language_module and not defined $year
!ll&&!rl&&r
000
MC/DC0%0/2
$use_date_language_module and not defined $year
$use_date_language_module not defined $year
Truth table0%0/3
A and not(B)
A= $use_date_language_moduleB= not defined $year
ABresult
0X0
100
111
1084 0 ▶ unless ( _date_language_installed () ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_date_language_installed()) { } 0 0 0
1085 0 DBUG_PRINT ("INFO", "Using Date::Language::str2time was requested, but it's not installed!");
1086 } else {
1087 0 DBUG_PRINT ("INFO", "Using Date::Language::str2time to attempt the parse!");
1088 0 eval {
1089 0 my $dl = Date::Language->new ( $last_language_edit_flags{language} );
1090 0 my $t = $dl->str2time ( $in_date );
1091 0 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) 0 0 0
1092 0 ($year, $month, $day) = (localtime ($t))[5,4,3];
1093 0 $year += 1900;
1094 0 $month += 1;
1095 }
1096 };
1097 }
1098 }
1099  
1100 # --------------------------------------------------------------------
1101 # We're done with parsing things. Now let's validate the results!
1102 # --------------------------------------------------------------------
1103  
1104 0 ▶ if ( ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $year) { } 0 0 0
1105 0 DBUG_PRINT ("ERROR", "No such date format is supported: %s", $in_date);
1106  
1107 # Else we're using a known date format ...
1108 } else {
1109 0 DBUG_PRINT ("FORMAT", "%s ==> %s ==> (Y:%s, M:%s, D:%s, Sep:%s)",
1110 $fmt, $in_date, $year, $month, $day, $s1);
1111  
1112 # It's not a valid date if the separaters are different ...
1113 # Shouldn't be possible any more unless it's spaces.
1114 # (Hence we die if it happens)
1115 0 ▶ if ( $s1 ne $s2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 ne $s2) 0 0 0
1116 0 ▶ unless ( $s1 =~ m/^\s*$/ && $s2 =~ m/^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s1 =~ /^\s*$/ and $s2 =~ /^\s*$/) 0 0 0
Condition0%0/3
$s1 =~ /^\s*$/ and $s2 =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$s1 =~ /^\s*$/ and $s2 =~ /^\s*$/
$s1 =~ /^\s*$/ $s2 =~ /^\s*$/
Truth table0%0/3
A and B
A= $s1 =~ /^\s*$/B= $s2 =~ /^\s*$/
ABresult
0X0
100
111
1117 0 die ("BUG: Separators are different ($s1 vs $s2)\n");
1118 }
1119 }
1120  
1121 # Now let's validate the results ...
1122 # Trim leading/trailing spaces ...
1123 0 ▶ $day = $1 if ( $day =~ m/^\s*(.*)\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $day =~ /^\s*(.*)\s*$/ 0 0 0
1124  
1125 0 return DBUG_RETURN ( _check_if_good_date ($in_date, $year, $month, $day) );
1126 }
1127  
1128 0 DBUG_RETURN ( undef ); # Invalid date ...
1129 }
1130  
1131  
1132 sub parse_date
1133 2887 ▶{
Subroutine parse_date: called CC=12 SCAR=25.1
Pod documented
1134 2887 DBUG_ENTER_FUNC ( @_ );
1135 2887 my $in_date = shift; # A potential date in an unknown format ...
1136 2887 my $date_format_options = shift; # A comma separated list of fmt ids ...
1137 2887 ▶ my $use_date_language_module = shift || 0;
Condition100%2/2
shift() || 0
l!l
22885
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1138 2887 ▶ my $allow_2_digit_years = shift || 0;
Condition100%2/2
shift() || 0
l!l
285730
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1139  
1140 2887 $in_date = lcx ($in_date); # Make sure always in lower case ...
1141  
1142 2887 my ($month, $month_digits) = _find_month_in_string ( $in_date );
1143 2887 ▶ my ($dom, $dom_digits) = _find_day_of_month_in_string ( $in_date, $month_digits,
Branch: 1 branch
BranchTrueFalseTotal
$month_digits ? : 106 2781 2887
1144 $month_digits ? undef : $month );
1145  
1146 2887 my $out_str;
1147  
1148 2887 ▶ if ( $month_digits && $dom_digits ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($month_digits and $dom_digits) { } 106 2781 2887
elsif ($month_digits) { } 0 2781 2781
elsif ($dom_digits) { } 1816 965 2781
Condition66%2/3
$month_digits and $dom_digits
!ll&&!rl&&r
27810106
MC/DC50%1/2
$month_digits and $dom_digits
$month_digits $dom_digits
Truth table66%2/3
A and B
A= $month_digitsB= $dom_digits
ABresult
0X0
100
111
1149 106 $out_str = _month_num_day_num ( $in_date, $month, $dom, $allow_2_digit_years, $date_format_options );
1150 } elsif ( $month_digits ) {
1151 0 $out_str = _month_num_day_str ( $in_date, $month, $dom, $allow_2_digit_years );
1152 } elsif ( $dom_digits ) {
1153 1816 $out_str = _month_str_day_num ( $in_date, $month, $dom, $allow_2_digit_years, $date_format_options );
1154 } else {
1155 965 $out_str = _month_str_day_str ( $in_date, $month, $dom, $allow_2_digit_years );
1156 }
1157  
1158 # --------------------------------------------------------------------
1159 # If my parsing didn't work try using Date::Language if it's installed.
1160 # Keep after my checks so that things are consistent when this module
1161 # isn't installed. (No way to disable 2-digit year format here.)
1162 # --------------------------------------------------------------------
1163 2887 ▶ if ( $use_date_language_module && (! $out_str) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($use_date_language_module and not $out_str and _date_language_installed()) 2 2885 2887
Condition66%4/6
$use_date_language_module and not $out_str and _date_language_installed()
!ll&&!rl&&r
288502
$use_date_language_module and not $out_str
!ll&&!rl&&r
288502
MC/DC33%1/3
$use_date_language_module and not $out_str and _date_language_installed()
$use_date_language_module not $out_str _date_language_installed()
Truth table50%2/4
A and not(B) and C
A= $use_date_language_moduleB= not $out_strC= _date_language_installed()
ABCresult
0XX0
10X0
1100
1111
1164 _date_language_installed () ) {
1165 2 DBUG_PRINT ("INFO", "Using Date::Language::str2time to attempt parsing!");
1166 2 eval {
1167 2 my $dl = Date::Language->new ( $last_language_edit_flags{language} );
1168 2 my $t = $dl->str2time ( $in_date );
1169 2 ▶ if ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) 2 0 2
1170 2 my ($year, $month, $day) = (localtime ($t))[5,4,3];
1171 2 $year += 1900;
1172 2 $month += 1;
1173  
1174 2 $out_str = _check_if_good_date ($in_date, $year, $month, $day);
1175 }
1176 };
1177 }
1178  
1179 2887 DBUG_RETURN ($out_str); # undef or the date in YYYY-MM-DD format.
1180 }
1181  
1182 # --------------------------------------------------------------
1183 # No ambiguity here ... we have multiple text anchors ...
1184  
1185 sub _month_str_day_str
1186 965 ▶{
Subroutine _month_str_day_str: called CC=11 SCAR=28.6
1187 965 DBUG_ENTER_FUNC ( @_ );
1188 965 my $in_date = shift;
1189 965 my $month_str = shift;
1190 965 my $dom_str = shift;
1191 965 my $allow_2_digit_years = shift;
1192  
1193 965 my ($year, $s1, $month, $s2, $day );
1194  
1195 965 ▶ if ( $in_date =~ m/(^|\D)(${month_str})[.]?(.*?\D)(${dom_str})(.*?\D)(\d{4})($|\D)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)($month_str)[.]?(.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/) { } 489 476 965
elsif ($in_date =~ /(^|\D)($dom_str)(.+?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/) { } 0 476 476
elsif ($in_date =~ /(^|\D)(\d{4})(\D.*?)($month_str)[.]?(.*?\D)($dom_str)($|\D)/) { } 0 476 476
1196 489 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # American format ...
1197  
1198 } elsif ($in_date =~ m/(^|\D)(${dom_str})(.+?)(${month_str})[.]?(.*?\D)(\d{4})($|\D)/ ) {
1199 0 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # European format ...
1200  
1201 } elsif ( $in_date =~ m/(^|\D)(\d{4})(\D.*?)(${month_str})[.]?(.*?\D)(${dom_str})($|\D)/ ) {
1202 0 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 ); # ISO format ...
1203 }
1204  
1205 965 ▶ if ( $allow_2_digit_years && ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_2_digit_years and not defined $year) 476 489 965
Condition66%2/3
$allow_2_digit_years and not defined $year
!ll&&!rl&&r
0489476
MC/DC50%1/2
$allow_2_digit_years and not defined $year
$allow_2_digit_years not defined $year
Truth table66%2/3
A and not(B)
A= $allow_2_digit_yearsB= not defined $year
ABresult
0X0
100
111
1206 476 ▶ if ( $in_date =~ m/(^|\D)(${month_str})[.]?(.*?\D)(${dom_str})(.*?[^:\d])(\d{2})($|[^:\d])/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)($month_str)[.]?(.*?\D)($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/) { } 476 0 476
elsif ($in_date =~ /(^|\D)($dom_str)(.+?)($month_str)[.]?(.*?[^:\d])(\d{2})($|[^:\d])/) { } 0 0 0
elsif ($in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?)($month_str)[.]?(.*?\D)($dom_str)($|\D)/) { } 0 0 0
1207 476 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # American format ...
1208  
1209 } elsif ($in_date =~ m/(^|\D)(${dom_str})(.+?)(${month_str})[.]?(.*?[^:\d])(\d{2})($|[^:\d])/ ) {
1210 0 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # European format ...
1211  
1212 } elsif ( $in_date =~ m/(^|[^:\d])(\d{2})([^:\d].*?)(${month_str})[.]?(.*?\D)(${dom_str})($|\D)/ ) {
1213 0 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 ); # ISO format ...
1214 }
1215  
1216 476 ▶ $year = make_it_a_4_digit_year ( $year ) if (defined $year);
Branch: 1 branch
BranchTrueFalseTotal
if defined $year 476 0 476
1217 } # End if allowing 2-digit years ...
1218  
1219 965 ▶ if ( defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $year) 965 0 965
1220 965 return DBUG_RETURN ( _check_if_good_date ($in_date, $year, $month, $day) );
1221 }
1222  
1223 0 DBUG_RETURN ( undef );
1224 }
1225  
1226 # --------------------------------------------------------------
1227 # With a month anchor still not too ambiguous.
1228  
1229 sub _tst_4_YY
1230 241 ▶{
Subroutine _tst_4_YY: called CC=2 SCAR=6.9
1231 241 my $sep = shift;
1232 241 ▶ my $res = ( $sep =~ m/\s\d{1,2}\s/ ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$sep =~ /\s\d{1,2}\s/ ? : 8 233 241
1233 241 return ($res);
1234 }
1235  
1236 sub _month_str_day_num
1237 1816 ▶{
Subroutine _month_str_day_num: called CC=17 SCAR=28.4
1238 1816 DBUG_ENTER_FUNC ( @_ );
1239 1816 my $in_date = shift;
1240 1816 my $month_str = shift;
1241 1816 my $dom_num = shift;
1242 1816 my $allow_2_digit_years = shift;
1243 1816 my $date_format_options = shift;
1244  
1245 1816 my ($year, $s1, $month, $s2, $day );
1246  
1247 # American format ...
1248 1816 ▶ if ( $in_date =~ m/(^|\D)(${month_str})[.]?([^\d]*?\D)(${dom_num})(\D)(\d{4})($|\D)/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D)(\d{4})($|\D)/) { } 76 1740 1816
elsif ($in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)) { } 212 1528 1740
elsif ($in_date =~ /(^|\D)($dom_num)(\D*?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)) { } 21 1507 1528
elsif ($in_date =~ /(^|\D)(\d{4})(\D*?)($month_str)[.]?(.*?\D)($dom_num)($|\D)/) { } 648 859 1507
1249 76 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1250 76 DBUG_PRINT ("AMERICAN-1", "${month}/${day}/${year} -- ($s1) ($s2)");
1251  
1252 # American format ...
1253 ▶ } elsif ( $in_date =~ m/(^|\D)(${month_str})[.]?([^\d]*?\D)(${dom_num})(\D.*?\D)(\d{4})($|\D)/ &&
Condition66%2/3
$in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)
!ll&&!rl&&r
15280212
MC/DC50%1/2
$in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)
$in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D.*?\D)(\d{4})($|\D)/ _tst_4_YY($5)
Truth table66%2/3
A and B
A= $in_date =~ /(^|\D)($month_str)[.]?([^\d]*?\D)($dom_num)(\D.*?\D)(\d{4})($|\D)/B= _tst_4_YY($5)
ABresult
0X0
100
111
1254 _tst_4_YY ( $5 ) ) {
1255 212 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1256 212 DBUG_PRINT ("AMERICAN-2", "${month}/${day}/${year} -- ($s1) ($s2)");
1257  
1258 # European format ...
1259 ▶ } elsif ($in_date =~ m/(^|\D)(${dom_num})(\D*?)(${month_str})[.]?(.*?\D)(\d{4})($|\D)/ &&
Condition100%3/3
$in_date =~ /(^|\D)($dom_num)(\D*?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)
!ll&&!rl&&r
1499821
MC/DC100%2/2
$in_date =~ /(^|\D)($dom_num)(\D*?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/ and _tst_4_YY($5)
$in_date =~ /(^|\D)($dom_num)(\D*?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/ _tst_4_YY($5)
Truth table100%3/3
A and B
A= $in_date =~ /(^|\D)($dom_num)(\D*?)($month_str)[.]?(.*?\D)(\d{4})($|\D)/B= _tst_4_YY($5)
ABresult
0X0
100
111
1260 _tst_4_YY ( $5 ) ) {
1261 21 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1262 21 DBUG_PRINT ("EUROPEAN", "${day}/${month}/${year} -- ($s1) ($s2)");
1263  
1264 # ISO format ...
1265 } elsif ( $in_date =~ m/(^|\D)(\d{4})(\D*?)(${month_str})[.]?(.*?\D)(${dom_num})($|\D)/ ) {
1266 648 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1267 648 DBUG_PRINT ("ISO", "${year}/${month}/${day} -- ($s1) ($s2)");
1268 }
1269  
1270 1816 ▶ if ( $allow_2_digit_years && ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_2_digit_years and not defined $year) 859 957 1816
Condition100%3/3
$allow_2_digit_years and not defined $year
!ll&&!rl&&r
18939859
MC/DC100%2/2
$allow_2_digit_years and not defined $year
$allow_2_digit_years not defined $year
Truth table100%3/3
A and not(B)
A= $allow_2_digit_yearsB= not defined $year
ABresult
0X0
100
111
1271 # American format ...
1272 859 ▶ if ( $in_date =~ m/(^|\D)(${month_str})[.]?(.*?[^:\d])(${dom_num})([^:\d])(\d{2})($|[^:\d])/ ||
Branch: 4 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/) { } 182 677 859
elsif ($in_date =~ /(^|\D)($dom_num)([^:\d].*?)($month_str)[.]?(.*?[^:\d])($dom_num)($|[^:\d])/) { } 9 668 677
elsif ($in_date =~ /(^|\D)($dom_num)([^:\d].*?)($month_str)[.]?(.*?[^:\d])(\d{2})($|[^:\d])/) { } 664 4 668
elsif ($in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?)($month_str)[.]?(.*?[^:\d])($dom_num)($|[^:\d])/) { } 0 4 4
Condition100%3/3
$in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
l!l&&r!l&&!r
2180677
MC/DC100%2/2
$in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
$in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d])(\d{2})($|[^:\d])/ $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
Truth table100%3/3
A or B
A= $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d])(\d{2})($|[^:\d])/B= $in_date =~ /(^|\D)($month_str)[.]?(.*?[^:\d])($dom_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
ABresult
1X1
011
000
1273 $in_date =~ m/(^|\D)(${month_str})[.]?(.*?[^:\d])(${dom_num})([^:\d].*?[^:\d])(\d{2})($|[^:\d])/ ) {
1274 182 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1275 182 $year = make_it_a_4_digit_year ( $year );
1276  
1277 # Ambiguous ... Either ISO or European, so must use hint ...
1278 } elsif ($in_date =~ m/(^|\D)(${dom_num})([^:\d].*?)(${month_str})[.]?(.*?[^:\d])(${dom_num})($|[^:\d])/ ) {
1279 9 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1280 9 my $yymmdd = sprintf ("%02d%02d%02d", $year, $Months{lcx($month)}, $day);
1281 9 my @order;
1282 9 foreach ( split (/\s*,\s*/, $date_format_options) ) {
1283 27 ▶ push (@order, $_) if ( $_ != 2 ); # Drop American format ...
Branch: 1 branch
BranchTrueFalseTotal
if $_ != 2 18 9 27
1284 }
1285 9 ($year, $month, $day) = parse_6_digit_date ( $yymmdd, join(",", @order) );
1286  
1287 # European format ...
1288 } elsif ($in_date =~ m/(^|\D)(${dom_num})([^:\d].*?)(${month_str})[.]?(.*?[^:\d])(\d{2})($|[^:\d])/ ) {
1289 664 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 );
1290 664 $year = make_it_a_4_digit_year ( $year );
1291  
1292 # ISO format ...
1293 } elsif ( $in_date =~ m/(^|[^:\d])(\d{2})([^:\d].*?)(${month_str})[.]?(.*?[^:\d])(${dom_num})($|[^:\d])/ ) {
1294 0 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1295 0 $year = make_it_a_4_digit_year ( $year );
1296 }
1297 } # End if allowing 2-digit years ...
1298  
1299 1816 ▶ if ( defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $year) 1812 4 1816
1300 1812 return DBUG_RETURN ( _check_if_good_date ($in_date, $year, $month, $day) );
1301 }
1302  
1303 4 DBUG_RETURN ( undef );
1304 }
1305  
1306 # --------------------------------------------------------------
1307 # Getting a bit more problematic ...
1308  
1309 sub _month_num_day_str
1310 0 ▶{
Subroutine _month_num_day_str: not called CC=21 SCAR=61.4
1311 0 DBUG_ENTER_FUNC ( @_ );
1312 0 my $in_date = shift;
1313 0 my $month_num = shift;
1314 0 my $dom_str = shift;
1315 0 my $allow_2_digit_years = shift;
1316  
1317 0 my ($year, $s1, $month, $s2, $day );
1318  
1319 0 ▶ if ( $in_date =~ m/(^|[^:\d])(${month_num})(\D)(${dom_str})(.*?\D)(\d{4})($|\D)/ ||
Branch: 3 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|[^:\d])($month_num)(\D)($dom_str)(.*?\D)(\d{4})($|\D)/ or $in_date =~ /(^|[^:\d])($month_num)(\D.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/) { } 0 0 0
elsif ($in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D)(\d{4})($|\D)/ or $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D.*?\D)(\d{4})($|\D)/) { } 0 0 0
elsif ($in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D.*?\D)($dom_str)($|\D)/) { } 0 0 0
Condition0%0/3
$in_date =~ /(^|[^:\d])($month_num)(\D)($dom_str)(.*?\D)(\d{4})($|\D)/ or $in_date =~ /(^|[^:\d])($month_num)(\D.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_date =~ /(^|[^:\d])($month_num)(\D)($dom_str)(.*?\D)(\d{4})($|\D)/ or $in_date =~ /(^|[^:\d])($month_num)(\D.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/
$in_date =~ /(^|[^:\d])($month_num)(\D)($dom_str)(.*?\D)(\d{4})($|\D)/ $in_date =~ /(^|[^:\d])($month_num)(\D.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/
Truth table0%0/3
A or B
A= $in_date =~ /(^|[^:\d])($month_num)(\D)($dom_str)(.*?\D)(\d{4})($|\D)/B= $in_date =~ /(^|[^:\d])($month_num)(\D.*?\D)($dom_str)(.*?\D)(\d{4})($|\D)/
ABresult
1X1
011
000
1320 $in_date =~ m/(^|[^:\d])(${month_num})(\D.*?\D)(${dom_str})(.*?\D)(\d{4})($|\D)/ ) {
1321 0 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # American format ...
1322  
1323 ▶ } elsif ($in_date =~ m/(^|\D)(${dom_str})(.*?\D)(${month_num})(\D)(\d{4})($|\D)/ ||
Condition0%0/3
$in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D)(\d{4})($|\D)/ or $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D.*?\D)(\d{4})($|\D)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D)(\d{4})($|\D)/ or $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D.*?\D)(\d{4})($|\D)/
$in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D)(\d{4})($|\D)/ $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D.*?\D)(\d{4})($|\D)/
Truth table0%0/3
A or B
A= $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D)(\d{4})($|\D)/B= $in_date =~ /(^|\D)($dom_str)(.*?\D)($month_num)(\D.*?\D)(\d{4})($|\D)/
ABresult
1X1
011
000
1324 $in_date =~ m/(^|\D)(${dom_str})(.*?\D)(${month_num})(\D.*?\D)(\d{4})($|\D)/ ) {
1325 0 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # European format ...
1326  
1327 ▶ } elsif ( $in_date =~ m/(^|\D)(\d{4})(\D)(${month_num})(\D)(${dom_str})($|\D)/ ||
Condition0%0/9
$in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D.*?\D)($dom_str)($|\D)/
l!l&&r!l&&!r
000
$in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/
l!l&&r!l&&!r
000
$in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/
l!l&&r!l&&!r
000
MC/DC0%0/4
$in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/ or $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D.*?\D)($dom_str)($|\D)/
$in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/ $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/ $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/ $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D.*?\D)($dom_str)($|\D)/
Truth table0%0/5
A or B or C or D
A= $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D)($dom_str)($|\D)/B= $in_date =~ /(^|\D)(\d{4})(\D)($month_num)(\D.*?\D)($dom_str)($|\D)/C= $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D)($dom_str)($|\D)/D= $in_date =~ /(^|\D)(\d{4})(\D.*?\D)($month_num)(\D.*?\D)($dom_str)($|\D)/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1328 $in_date =~ m/(^|\D)(\d{4})(\D)(${month_num})(\D.*?\D)(${dom_str})($|\D)/ ||
1329 $in_date =~ m/(^|\D)(\d{4})(\D.*?\D)(${month_num})(\D)(${dom_str})($|\D)/ ||
1330 $in_date =~ m/(^|\D)(\d{4})(\D.*?\D)(${month_num})(\D.*?\D)(${dom_str})($|\D)/ ) {
1331 0 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 ); # ISO format ...
1332 }
1333  
1334 0 ▶ if ( $allow_2_digit_years && ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_2_digit_years and not defined $year) 0 0 0
Condition0%0/3
$allow_2_digit_years and not defined $year
!ll&&!rl&&r
000
MC/DC0%0/2
$allow_2_digit_years and not defined $year
$allow_2_digit_years not defined $year
Truth table0%0/3
A and not(B)
A= $allow_2_digit_yearsB= not defined $year
ABresult
0X0
100
111
1335 0 ▶ if ( $in_date =~ m/(^|\D)(${month_num})([^:\d])(${dom_str})(.*?[^:\d])(\d{2})($|[^:\d])/ ||
Branch: 3 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)($month_num)([^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_num)([^:\d].*?[^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/) { } 0 0 0
elsif ($in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/) { } 0 0 0
elsif ($in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/) { } 0 0 0
Condition0%0/3
$in_date =~ /(^|\D)($month_num)([^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_num)([^:\d].*?[^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_date =~ /(^|\D)($month_num)([^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($month_num)([^:\d].*?[^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/
$in_date =~ /(^|\D)($month_num)([^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/ $in_date =~ /(^|\D)($month_num)([^:\d].*?[^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/
Truth table0%0/3
A or B
A= $in_date =~ /(^|\D)($month_num)([^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/B= $in_date =~ /(^|\D)($month_num)([^:\d].*?[^:\d])($dom_str)(.*?[^:\d])(\d{2})($|[^:\d])/
ABresult
1X1
011
000
1336 $in_date =~ m/(^|\D)(${month_num})([^:\d].*?[^:\d])(${dom_str})(.*?[^:\d])(\d{2})($|[^:\d])/ ) {
1337 0 ($month, $s1, $day, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # American format ...
1338  
1339 ▶ } elsif ($in_date =~ m/(^|\D)(${dom_str})(.*?[^:\d])(${month_num})([^:\d])(\d{2})($|[^:\d])/ ||
Condition0%0/3
$in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d])(\d{2})($|[^:\d])/ or $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
$in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d])(\d{2})($|[^:\d])/ $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
Truth table0%0/3
A or B
A= $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d])(\d{2})($|[^:\d])/B= $in_date =~ /(^|\D)($dom_str)(.*?[^:\d])($month_num)([^:\d].*?[^:\d])(\d{2})($|[^:\d])/
ABresult
1X1
011
000
1340 $in_date =~ m/(^|\D)(${dom_str})(.*?[^:\d])(${month_num})([^:\d].*?[^:\d])(\d{2})($|[^:\d])/ ) {
1341 0 ($day, $s1, $month, $s2, $year ) = ( $2, $3, $4, $5, $6 ); # European format ...
1342  
1343 ▶ } elsif ( $in_date =~ m/(^|[^:\d])(\d{2})([^:\d])(${month_num})([^:\d])(${dom_str})($|\D)/ ||
Condition0%0/9
$in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/
l!l&&r!l&&!r
000
$in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/
l!l&&r!l&&!r
000
$in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/
l!l&&r!l&&!r
000
MC/DC0%0/4
$in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/ or $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/
$in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/ $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/ $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/ $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/
Truth table0%0/5
A or B or C or D
A= $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d])($dom_str)($|\D)/B= $in_date =~ /(^|[^:\d])(\d{2})([^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/C= $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d])($dom_str)($|\D)/D= $in_date =~ /(^|[^:\d])(\d{2})([^:\d].*?[^:\d])($month_num)([^:\d].*?[^:\d])($dom_str)($|\D)/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1344 $in_date =~ m/(^|[^:\d])(\d{2})([^:\d])(${month_num})([^:\d].*?[^:\d])(${dom_str})($|\D)/ ||
1345 $in_date =~ m/(^|[^:\d])(\d{2})([^:\d].*?[^:\d])(${month_num})([^:\d])(${dom_str})($|\D)/ ||
1346 $in_date =~ m/(^|[^:\d])(\d{2})([^:\d].*?[^:\d])(${month_num})([^:\d].*?[^:\d])(${dom_str})($|\D)/ ) {
1347 0 ($year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 ); # ISO format ...
1348 }
1349  
1350 0 ▶ $year = make_it_a_4_digit_year ( $year ) if (defined $year);
Branch: 1 branch
BranchTrueFalseTotal
if defined $year 0 0 0
1351 } # End if allowing 2-digit years ...
1352  
1353 0 ▶ if ( defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $year) 0 0 0
1354 0 return DBUG_RETURN ( _check_if_good_date ($in_date, $year, $month, $day) );
1355 }
1356  
1357 0 DBUG_RETURN ( undef );
1358 }
1359  
1360 # --------------------------------------------------------------
1361 # A very ambiguous format ... and much, much messier!
1362  
1363 sub _month_num_day_num
1364 106 ▶{
Subroutine _month_num_day_num: called CC=9 SCAR=22.0
1365 106 DBUG_ENTER_FUNC ( @_ );
1366 106 my $in_date = shift;
1367 106 my $month_num = shift;
1368 106 my $dom_num = shift;
1369 106 my $allow_2_digit_years = shift;
1370 106 my $date_format_options = shift;
1371  
1372 106 my ($year, $s1, $month, $s2, $day );
1373  
1374 # Unknown format, use hint to decide ...
1375 106 ▶ if ( $in_date =~ m/(^|\D)(\d{8})($|\D)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)(\d{8})($|\D)/) { } 12 94 106
elsif ($in_date =~ /(^|\D)(\d{1,2})(\D+)(\d{1,2})(\D+)(\d{4})(\D|$)/) { } 42 52 94
elsif ($in_date =~ /(^|\D)(\d{4})(\D+)($month_num)(\D+)($dom_num)(\D|$)/) { } 21 31 52
1376 12 ( $year, $month, $day ) = parse_8_digit_date ( $2, $date_format_options, 0 );
1377 12 $s1 = $s2 = "";
1378  
1379 # American or European Format, use hint to decide ...
1380 } elsif ( $in_date =~ m/(^|\D)(\d{1,2})(\D+)(\d{1,2})(\D+)(\d{4})(\D|$)/ ) {
1381 42 ( $s1, $s2 ) = ( $3, $5 );
1382 42 my $date = sprintf ("%02d%02d%04d", $2, $4, $6);
1383 42 ( $year, $month, $day ) = parse_8_digit_date ( $date, $date_format_options, 1 );
1384  
1385 # ISO Format ...
1386 } elsif ( $in_date =~ m/(^|\D)(\d{4})(\D+)(${month_num})(\D+)(${dom_num})(\D|$)/ ) {
1387 21 ( $year, $s1, $month, $s2, $day ) = ( $2, $3, $4, $5, $6 );
1388 }
1389  
1390  
1391 106 ▶ if ( $allow_2_digit_years && ! defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_2_digit_years and not defined $year) 19 87 106
Condition100%3/3
$allow_2_digit_years and not defined $year
!ll&&!rl&&r
127519
MC/DC100%2/2
$allow_2_digit_years and not defined $year
$allow_2_digit_years not defined $year
Truth table100%3/3
A and not(B)
A= $allow_2_digit_yearsB= not defined $year
ABresult
0X0
100
111
1392 # Unknown format, use hint to decide ...
1393 19 ▶ if ( $in_date =~ m/(^|\D)(\d{6})($|\D)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($in_date =~ /(^|\D)(\d{6})($|\D)/) { } 3 16 19
elsif ($in_date =~ /(^|[^:\d])(\d{1,2})([^:\d]+)(\d{1,2})([^:\d]+)(\d{1,2})([^:\d]|$)/) { } 14 2 16
1394 3 ( $year, $month, $day ) = parse_6_digit_date ( $2, $date_format_options );
1395 3 $s1 = $s2 = "";
1396  
1397 # Unknown format, use hint to decide ...
1398 } elsif ( $in_date =~ m/(^|[^:\d])(\d{1,2})([^:\d]+)(\d{1,2})([^:\d]+)(\d{1,2})([^:\d]|$)/ ) {
1399 14 ( $s1, $s2 ) = ( $3, $5 );
1400 14 my $date = sprintf ("%02d%02d%02d", $2, $4, $6);
1401 14 ( $year, $month, $day ) = parse_6_digit_date ( $date, $date_format_options );
1402 }
1403 } # End if allowing 2-digit years ...
1404  
1405 106 ▶ if ( defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $year) 92 14 106
1406 92 return DBUG_RETURN ( _check_if_good_date ($in_date, $year, $month, $day) );
1407 }
1408  
1409 14 DBUG_RETURN ( undef );
1410 }
1411  
1412  
1413 # --------------------------------------------------------------
1414 # Always returns date in ISO format if it's good!
1415 # Or undef if a bad date!
1416  
1417 sub _check_if_good_date
1418 2871 ▶{
Subroutine _check_if_good_date: called CC=13 SCAR=37.8
1419 2871 DBUG_ENTER_FUNC ( @_ );
1420 2871 my $in_str = shift;
1421 2871 my $year = shift;
1422 2871 my $month = shift;
1423 2871 my $day = shift;
1424  
1425 # Strip off any leading zeros so we can use the hashes for validation ...
1426 2871 $month =~ s/^0+//;
1427 2871 $day =~ s/^0+//;
1428  
1429 # Standardize it ... (with digits only!)
1430 2871 $month = $Months{lcx($month)};
1431 2871 $day = $Days{lcx($day)};
1432  
1433 # Helpfull when dealing with foreign languages.
1434 2871 my $err_msg;
1435 2871 ▶ if ( defined $month && defined $day ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $month and defined $day) { } 2871 0 2871
elsif (defined $month) { } 0 0 0
elsif (defined $day) { } 0 0 0
Condition33%1/3
defined $month and defined $day
!ll&&!rl&&r
002871
MC/DC0%0/2
defined $month and defined $day
defined $month defined $day
Truth table33%1/3
A and B
A= defined $monthB= defined $day
ABresult
0X0
100
111
1436 ; # Good date!
1437 } elsif ( defined $month ) {
1438 0 $err_msg = "Just the day of month is bad.";
1439 } elsif ( defined $day ) {
1440 0 $err_msg = "Just the month is bad.";
1441 } else {
1442 0 $err_msg = "Both the month and day are bad.";
1443 }
1444  
1445 2871 ▶ unless ( $err_msg ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err_msg) 2871 0 2871
1446 2871 ▶ if ( 1 <= $day && $day <= $days_in_months[$month] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (1 <= $day and $day <= $days_in_months[$month]) { } 2871 0 2871
elsif ($month == 2 and $day == 29) { } 0 0 0
Condition33%1/3
1 <= $day and $day <= $days_in_months[$month]
!ll&&!rl&&r
002871
MC/DC0%0/2
1 <= $day and $day <= $days_in_months[$month]
1 <= $day $day <= $days_in_months[$month]
Truth table33%1/3
A and B
A= 1 <= $dayB= $day <= $days_in_months[$month]
ABresult
0X0
100
111
1447 ; # It's a good date ...
1448 ▶ } elsif ( $month == 2 && $day == 29 ) {
Condition0%0/3
$month == 2 and $day == 29
!ll&&!rl&&r
000
MC/DC0%0/2
$month == 2 and $day == 29
$month == 2 $day == 29
Truth table0%0/3
A and B
A= $month == 2B= $day == 29
ABresult
0X0
100
111
1449 0 my $leap = _is_leap_year ($year);
1450 0 ▶ $year = undef unless ( $leap );
Branch: 1 branch
BranchTrueFalseTotal
unless $leap 0 0 0
1451 } else {
1452 0 $year = undef;
1453 }
1454 2871 ▶ unless ( defined $year ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 2871 2871
1455 0 $err_msg = "The day of month is out of range.";
1456 }
1457 }
1458  
1459 2871 ▶ if ( $err_msg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_msg) 0 2871 2871
1460 0 DBUG_PRINT ("ERROR", "'%s' was an invalid date!\n%s", $in_str, $err_msg);
1461 0 DBUG_PRINT ("BAD", "%s-%s-%s", $year, $month, $day);
1462 0 return ( DBUG_RETURN (undef) );
1463 }
1464  
1465 2871 DBUG_RETURN ( sprintf ("%04d-%02d-%02d", $year, $month, $day) );
1466 }
1467  
1468 # --------------------------------------------------------------
1469 sub _find_month_in_string
1470 2887 ▶{
Subroutine _find_month_in_string: called CC=8 SCAR=21.0
1471 2887 DBUG_ENTER_FUNC (@_);
1472 2887 my $date_str = shift;
1473  
1474 2887 my $month;
1475 2887 my $digits = 0;
1476  
1477 2887 ▶ my @lst = sort { length($b) <=> length($a) || $a cmp $b } keys %Months;
Condition66%2/3
length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
2248461690610
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a $a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
ABresult
1X1
011
000
1478  
1479 2887 foreach my $m ( @lst ) {
1480 # Ignore numeric keys, can't get the correct one from string ...
1481 37127 ▶ next if ( $m =~ m/^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $m =~ /^\d+$/ 1668 35459 37127
1482  
1483 my $flag1 = ( $last_language_edit_flags{month_period} &&
1484 35459 ▶ $m =~ s/[.]/\\./g );
Condition33%1/3
$last_language_edit_flags{'month_period'} && $m =~ s/[.]/\\./g
!ll&&!rl&&r
3545900
MC/DC0%0/2
$last_language_edit_flags{'month_period'} && $m =~ s/[.]/\\./g
$last_language_edit_flags{'month_period'} $m =~ s/[.]/\\./g
Truth table33%1/3
A && B
A= $last_language_edit_flags{'month_period'}B= $m =~ s/[.]/\\./g
ABresult
0X0
100
111
1485  
1486 35459 ▶ if ( $date_str =~ m/(${m})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date_str =~ /($m)/) 2781 32678 35459
1487 2781 $month = $1;
1488 2781 ▶ $month =~ s/[.]/\\./g if ( $flag1 );
Branch: 1 branch
BranchTrueFalseTotal
if $flag1 0 2781 2781
1489 2781 last;
1490 }
1491 }
1492  
1493 # Allow any number between 1 and 12 ...
1494 2887 ▶ unless ( $month ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($month) 106 2781 2887
1495 106 $month = "[1-9]|0[1-9]|1[0-2]";
1496 106 $digits = 1;
1497 }
1498  
1499 2887 DBUG_RETURN ( $month, $digits ); # Suitable for use in a RegExpr.
1500 }
1501  
1502 # --------------------------------------------------------------
1503 sub _find_day_of_month_in_string
1504 2887 ▶{
Subroutine _find_day_of_month_in_string: called CC=13 SCAR=26.4
1505 2887 DBUG_ENTER_FUNC (@_);
1506 2887 my $date_str = shift;
1507 2887 my $skip_period = shift; # Skip entries ending in '.' like 17.!
1508 2887 my $month_str = shift; # Will be undef if skip_period is true!
1509  
1510 2887 my $day;
1511 2887 my $digits = 0;
1512  
1513 2887 ▶ my @lst = sort { length($b) <=> length($a) || $a cmp $b } keys %Days;
Condition66%2/3
length $b <=> length $a || $a cmp $b
l!l&&r!l&&!r
2399484801610
MC/DC0%0/2
length $b <=> length $a || $a cmp $b
length $b <=> length $a $a cmp $b
Truth table66%2/3
A || B
A= length $b <=> length $aB= $a cmp $b
ABresult
1X1
011
000
1514  
1515 2887 ▶ my $all_digits = $skip_period ? "^\\d+[.]?\$" : "^\\d+\$";
Branch: 1 branch
BranchTrueFalseTotal
$skip_period ? : 106 2781 2887
1516  
1517 2887 foreach my $dom ( @lst ) {
1518 # Ignore numeric keys, can't get the correct one from string ...
1519 119291 ▶ next if ( $dom =~ m/${all_digits}/ );
Branch: 1 branch
BranchTrueFalseTotal
if $dom =~ /$all_digits/ 64146 55145 119291
1520  
1521 my $flag1 = ( $last_language_edit_flags{dsuf_period} &&
1522 55145 ▶ $dom =~ s/[.]/\\./g );
Condition66%2/3
$last_language_edit_flags{'dsuf_period'} && $dom =~ s/[.]/\\./g
!ll&&!rl&&r
5277502370
MC/DC50%1/2
$last_language_edit_flags{'dsuf_period'} && $dom =~ s/[.]/\\./g
$last_language_edit_flags{'dsuf_period'} $dom =~ s/[.]/\\./g
Truth table66%2/3
A && B
A= $last_language_edit_flags{'dsuf_period'}B= $dom =~ s/[.]/\\./g
ABresult
0X0
100
111
1523  
1524 55145 ▶ if ( $month_str ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($month_str) { } 51859 3286 55145
elsif ($date_str =~ /($dom)/) { } 0 3286 3286
1525 # Makes sure dom doesn't match month name ...
1526 51859 $month_str =~ s/[.]/\\./g;
1527 51859 ▶ if ( $date_str =~ m/${month_str}.*(${dom})/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($date_str =~ /$month_str.*($dom)/ or $date_str =~ /($dom).*$month_str/) 965 50894 51859
Condition66%2/3
$date_str =~ /$month_str.*($dom)/ or $date_str =~ /($dom).*$month_str/
l!l&&r!l&&!r
965050894
MC/DC50%1/2
$date_str =~ /$month_str.*($dom)/ or $date_str =~ /($dom).*$month_str/
$date_str =~ /$month_str.*($dom)/ $date_str =~ /($dom).*$month_str/
Truth table66%2/3
A or B
A= $date_str =~ /$month_str.*($dom)/B= $date_str =~ /($dom).*$month_str/
ABresult
1X1
011
000
1528 $date_str =~ m/(${dom}).*${month_str}/ ) {
1529 965 $day = $1;
1530 965 ▶ $day =~ s/[.]/\\./g if ( $flag1 );
Branch: 1 branch
BranchTrueFalseTotal
if $flag1 48 917 965
1531 965 last;
1532 }
1533  
1534 # There is no month name to worry about ...
1535 } elsif ( $date_str =~ m/(${dom})/ ) {
1536 0 $day = $1;
1537 0 ▶ $day =~ s/[.]/\\./g if ( $flag1 );
Branch: 1 branch
BranchTrueFalseTotal
if $flag1 0 0 0
1538 0 last;
1539 }
1540 }
1541  
1542 # Allow any number between 1 and 31 ...
1543 2887 ▶ unless ( $day ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($day) 1922 965 2887
1544 1922 $day = "[1-9]|0[1-9]|[12][0-9]|3[01]";
1545 1922 $digits = 1;
1546 }
1547  
1548 2887 DBUG_RETURN ( $day, $digits ); # Suitable for use in a RegExpr.
1549 }
1550  
1551 # ==============================================================
1552  
1553 =item adjust_future_cutoff ( $num_years );
1554  
1555 Changes the cutoff future date from B<30> years to I<$num_years>.
1556  
1557 Set to B<0> to disable years in the future!
1558  
1559 This affects all L<Advanced::Config> objects, not just the current one.
1560  
1561 =cut
1562  
1563 sub adjust_future_cutoff
1564 0 ▶{
Subroutine adjust_future_cutoff: not called CC=3 SCAR=24.8
Pod documented
1565 0 DBUG_ENTER_FUNC ( @_ );
1566 0 my $years = shift;
1567  
1568 0 ▶ if ( defined $years && $years =~ m/^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $years and $years =~ /^\d+$/) 0 0 0
Condition0%0/3
defined $years and $years =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $years and $years =~ /^\d+$/
defined $years $years =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $yearsB= $years =~ /^\d+$/
ABresult
0X0
100
111
1569 0 $global_cutoff_date = shift;
1570 }
1571  
1572 0 DBUG_VOID_RETURN ();
1573 }
1574  
1575  
1576 # ==============================================================
1577  
1578 =item $year = make_it_a_4_digit_year ( $two_digit_year );
1579  
1580 Used whenever this module needs to convert a two-digit year into a four-digit
1581 year.
1582  
1583 When it converts YY into YYYY, it will assume 20YY unless the
1584 resulting date is more than B<30> years in the future. Then it's 19YY.
1585  
1586 If you don't like this rule, use B<adjust_future_cutoff> to change
1587 this limit!
1588  
1589 =cut
1590  
1591 sub make_it_a_4_digit_year
1592 1348 ▶{
Subroutine make_it_a_4_digit_year: called CC=4 SCAR=14.0
Pod documented
1593 1348 DBUG_ENTER_FUNC ( @_ );
1594 1348 ▶ my $year = shift || 0; # Passed as a 2-digit year ...
Condition50%1/2
shift() || 0
l!l
13480
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1595  
1596 1348 $year += 2000; # Convert it to a 4-digit year ...
1597  
1598 # Get the current 4-digit year ...
1599 1348 my $this_yr = (localtime (time()))[5];
1600 1348 $this_yr += 1900;
1601  
1602 1348 ▶ if ( $this_yr < $year && ($year - $this_yr) >= $global_cutoff_date ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_yr < $year and $year - $this_yr >= $global_cutoff_date) 1317 31 1348
Condition66%2/3
$this_yr < $year and $year - $this_yr >= $global_cutoff_date
!ll&&!rl&&r
3101317
MC/DC50%1/2
$this_yr < $year and $year - $this_yr >= $global_cutoff_date
$this_yr < $year $year - $this_yr >= $global_cutoff_date
Truth table66%2/3
A and B
A= $this_yr < $yearB= $year - $this_yr >= $global_cutoff_date
ABresult
0X0
100
111
1603 1317 $year -= 100; # Make it last century instead.
1604 }
1605  
1606 1348 DBUG_RETURN ( $year );
1607 }
1608  
1609  
1610 # ==============================================================
1611  
1612 =item ($year, $month, $day) = parse_8_digit_date ( $date_str, $order[, $skip] );
1613  
1614 Looks for a valid date in an 8 digit string. It checks each of the formats below
1615 in the order specified by I<$order> until it hits something that looks like a
1616 valid date.
1617  
1618 (1) YYYYMMDD - ISO
1619 (2) MMDDYYYY - American
1620 (3) DDMMYYYY - European
1621  
1622 The I<$order> argument helps deal with ambiguities in the date. Its a comma
1623 separated list of numbers specifying to order to try out. Ex: 3,2,1 means
1624 try out the European date format 1st, then the American date format 2nd, and
1625 finally the ISO format 3rd. You could also just say I<$order> is B<3> and
1626 only accept European dates.
1627  
1628 It assumes its using the correct format when the date looks valid. It does this
1629 by validating the B<MM> is between 1 and 12 and that the B<DD> is between 1 and
1630 31. (Using the correct max for that month). And then assumes the year is
1631 always valid.
1632  
1633 If I<$skip> is a non-zero value it will skip over the B<ISO> format if it's
1634 listed in I<$order>.
1635  
1636 Returns 3 B<undef>'s if nothing looks good.
1637  
1638 =cut
1639  
1640 sub parse_8_digit_date
1641 54 ▶{
Subroutine parse_8_digit_date: called CC=19 SCAR=30.7
Pod documented
1642 54 DBUG_ENTER_FUNC ( @_ );
1643 54 my $date_str = shift;
1644 54 my $order = shift;
1645 54 ▶ my $skip_iso = shift || 0;
Condition100%2/2
shift() || 0
l!l
4212
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1646  
1647 54 my @order = split (/\s*,\s*/, $order);
1648 54 my @lbls = ( "", "YYYYMMDD - ISO", "MMDDYYYY - American", "DDMMYYYY - European" );
1649  
1650 54 my ( $year, $month, $day );
1651 54 foreach my $id ( @order ) {
1652 101 ▶ next unless ( defined $id && $id =~ m/^[123]$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and $id =~ /^[123]$/ 0 101 101
Condition33%1/3
defined $id and $id =~ /^[123]$/
!ll&&!rl&&r
00101
MC/DC0%0/2
defined $id and $id =~ /^[123]$/
defined $id $id =~ /^[123]$/
Truth table33%1/3
A and B
A= defined $idB= $id =~ /^[123]$/
ABresult
0X0
100
111
1653  
1654 101 my ( $y, $m, $d ) = ( 0, 0, 0 );
1655  
1656 101 ▶ if ( $id == 1 && (! $skip_iso) && # YYYYMMDD - ISO
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 1 and not $skip_iso and $date_str =~ /^(\d{4})(\d{2})(\d{2})$/) 12 89 101
Condition83%5/6
$id == 1 and not $skip_iso and $date_str =~ /^(\d{4})(\d{2})(\d{2})$/
!ll&&!rl&&r
89012
$id == 1 and not $skip_iso
!ll&&!rl&&r
474212
MC/DC66%2/3
$id == 1 and not $skip_iso and $date_str =~ /^(\d{4})(\d{2})(\d{2})$/
$id == 1 not $skip_iso $date_str =~ /^(\d{4})(\d{2})(\d{2})$/
Truth table75%3/4
A and not(B) and C
A= $id == 1B= not $skip_isoC= $date_str =~ /^(\d{4})(\d{2})(\d{2})$/
ABCresult
0XX0
10X0
1100
1111
1657 $date_str =~ m/^(\d{4})(\d{2})(\d{2})$/ ) {
1658 12 ( $y, $m, $d ) = ( $1, $2, $3 );
1659 }
1660 101 ▶ if ( $id == 2 && # MMDDYYYY - American
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 2 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/) 47 54 101
Condition66%2/3
$id == 2 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
!ll&&!rl&&r
54047
MC/DC50%1/2
$id == 2 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
$id == 2 $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
Truth table66%2/3
A and B
A= $id == 2B= $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
ABresult
0X0
100
111
1661 $date_str =~ m/^(\d{2})(\d{2})(\d{4})$/ ) {
1662 47 ( $m, $d, $y ) = ( $1, $2, $3 );
1663 }
1664 101 ▶ if ( $id == 3 && # DDMMYYYY - European
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 3 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/) 0 101 101
Condition33%1/3
$id == 3 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
!ll&&!rl&&r
10100
MC/DC0%0/2
$id == 3 and $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
$id == 3 $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
Truth table33%1/3
A and B
A= $id == 3B= $date_str =~ /^(\d{2})(\d{2})(\d{4})$/
ABresult
0X0
100
111
1665 $date_str =~ m/^(\d{2})(\d{2})(\d{4})$/ ) {
1666 0 ( $d, $m, $y ) = ( $1, $2, $3 );
1667 }
1668  
1669 101 ▶ if ( 1 <= $m && $m <= 12 && 1 <= $d && $d <= 31 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 <= $m and $m <= 12 and 1 <= $d and $d <= 31) 54 47 101
Condition77%7/9
1 <= $m and $m <= 12 and 1 <= $d and $d <= 31
!ll&&!rl&&r
47054
1 <= $m and $m <= 12 and 1 <= $d
!ll&&!rl&&r
47054
1 <= $m and $m <= 12
!ll&&!rl&&r
42554
MC/DC50%2/4
1 <= $m and $m <= 12 and 1 <= $d and $d <= 31
1 <= $m $m <= 12 1 <= $d $d <= 31
Truth table60%3/5
A and B and C and D
A= 1 <= $mB= $m <= 12C= 1 <= $dD= $d <= 31
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1670 54 DBUG_PRINT ("INFO", "Validating if using %s format.", $lbls[$id]);
1671 54 my $max = $days_in_months[$m];
1672 54 ▶ if ( $m == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m == 2) 3 51 54
1673 3 my $leap = _is_leap_year ($y);
1674 3 ▶ ++$max if ( $leap );
Branch: 1 branch
BranchTrueFalseTotal
if $leap 0 3 3
1675 }
1676  
1677 54 ▶ if ( $d <= $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= $max) 54 0 54
1678 54 ( $year, $month, $day ) = ( $y, $m, $d );
1679 54 last;
1680 }
1681 }
1682 }
1683  
1684 54 DBUG_RETURN ( $year, $month, $day );
1685 }
1686  
1687  
1688 # ==============================================================
1689  
1690 =item ($year, $month, $day) = parse_6_digit_date ( $date_str, $order );
1691  
1692 Looks for a valid date in an 6 digit string. It checks each of the formats below
1693 in the order specified by I<$order> until it hits something that looks like a
1694 valid date.
1695  
1696 (1) YYMMDD - ISO
1697 (2) MMDDYY - American
1698 (3) DDMMYY - European
1699  
1700 The I<$order> argument helps deal with ambiguities in the date. Its a comma
1701 separated list of numbers specifying to order to try out. Ex: 2,3,1 means
1702 try out the American date format 1st, then the European date format 2nd, and
1703 finally the ISO format 3rd. You could also just say I<$order> is B<2> and
1704 only accept European dates.
1705  
1706 So if you use the wrong order, more than likely you'll get the wrong date!
1707  
1708 It assumes its using the correct format when the date looks valid. It does this
1709 by validating the B<MM> is between 1 and 12 and that the B<DD> is between 1 and
1710 31. (Using the correct max for that month). And then assumes the year is
1711 always valid.
1712  
1713 Returns 3 B<undef>'s if nothing looks good.
1714  
1715 It always returns the year as a 4-digit year!
1716  
1717 =cut
1718  
1719 sub parse_6_digit_date
1720 26 ▶{
Subroutine parse_6_digit_date: called CC=24 SCAR=37.5
Pod documented
1721 26 DBUG_ENTER_FUNC ( @_ );
1722 26 my $date_str = shift;
1723 26 my $order = shift;
1724  
1725 26 my @order = split (/\s*,\s*/, $order);
1726 26 my @lbls = ( "", "YYMMDD - ISO", "MMDDYY - American", "DDMMYY - European" );
1727  
1728 26 my ( $year, $month, $day );
1729 26 ▶ if ( $date_str =~ m/^(\d{2})(\d{2})(\d{2})$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date_str =~ /^(\d{2})(\d{2})(\d{2})$/) 26 0 26
1730 26 my @part = ( $1, $2, $3 );
1731 26 foreach my $id ( @order ) {
1732 29 ▶ next unless ( defined $id && $id =~ m/^[123]$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and $id =~ /^[123]$/ 0 29 29
Condition33%1/3
defined $id and $id =~ /^[123]$/
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $id and $id =~ /^[123]$/
defined $id $id =~ /^[123]$/
Truth table33%1/3
A and B
A= defined $idB= $id =~ /^[123]$/
ABresult
0X0
100
111
1733  
1734 29 my ( $y, $m, $d ) = ( 0, 0, 0 );
1735  
1736 29 ▶ if ( $id == 1 && # YYMMDD - ISO
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 1 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[2] and $part[2] <= 31) 23 6 29
Condition75%9/12
$id == 1 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[2] and $part[2] <= 31
!ll&&!rl&&r
3323
$id == 1 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[2]
!ll&&!rl&&r
3026
$id == 1 and 1 <= $part[1] and $part[1] <= 12
!ll&&!rl&&r
3026
$id == 1 and 1 <= $part[1]
!ll&&!rl&&r
3026
MC/DC40%2/5
$id == 1 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[2] and $part[2] <= 31
$id == 1 1 <= $part[1] $part[1] <= 12 1 <= $part[2] $part[2] <= 31
Truth table50%3/6
A and B and C and D and E
A= $id == 1B= 1 <= $part[1]C= $part[1] <= 12D= 1 <= $part[2]E= $part[2] <= 31
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1737 1 <= $part[1] && $part[1] <= 12 &&
1738 1 <= $part[2] && $part[2] <= 31 ) {
1739 23 ( $m, $d, $y ) = ( $part[1], $part[2], $part[0] );
1740 }
1741 29 ▶ if ( $id == 2 && # MMDDYY - American
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 2 and 1 <= $part[0] and $part[0] <= 12 and 1 <= $part[1] and $part[1] <= 31) 3 26 29
Condition66%8/12
$id == 2 and 1 <= $part[0] and $part[0] <= 12 and 1 <= $part[1] and $part[1] <= 31
!ll&&!rl&&r
2603
$id == 2 and 1 <= $part[0] and $part[0] <= 12 and 1 <= $part[1]
!ll&&!rl&&r
2603
$id == 2 and 1 <= $part[0] and $part[0] <= 12
!ll&&!rl&&r
2603
$id == 2 and 1 <= $part[0]
!ll&&!rl&&r
2603
MC/DC20%1/5
$id == 2 and 1 <= $part[0] and $part[0] <= 12 and 1 <= $part[1] and $part[1] <= 31
$id == 2 1 <= $part[0] $part[0] <= 12 1 <= $part[1] $part[1] <= 31
Truth table33%2/6
A and B and C and D and E
A= $id == 2B= 1 <= $part[0]C= $part[0] <= 12D= 1 <= $part[1]E= $part[1] <= 31
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1742 1 <= $part[0] && $part[0] <= 12 &&
1743 1 <= $part[1] && $part[1] <= 31 ) {
1744 3 ( $m, $d, $y ) = ( $part[0], $part[1], $part[2] );
1745 }
1746 29 ▶ if ( $id == 3 && # DDMMYY - European
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 3 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[0] and $part[0] <= 31) 0 29 29
Condition33%4/12
$id == 3 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[0] and $part[0] <= 31
!ll&&!rl&&r
2900
$id == 3 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[0]
!ll&&!rl&&r
2900
$id == 3 and 1 <= $part[1] and $part[1] <= 12
!ll&&!rl&&r
2900
$id == 3 and 1 <= $part[1]
!ll&&!rl&&r
2900
MC/DC0%0/5
$id == 3 and 1 <= $part[1] and $part[1] <= 12 and 1 <= $part[0] and $part[0] <= 31
$id == 3 1 <= $part[1] $part[1] <= 12 1 <= $part[0] $part[0] <= 31
Truth table16%1/6
A and B and C and D and E
A= $id == 3B= 1 <= $part[1]C= $part[1] <= 12D= 1 <= $part[0]E= $part[0] <= 31
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1747 1 <= $part[1] && $part[1] <= 12 &&
1748 1 <= $part[0] && $part[0] <= 31 ) {
1749 0 ( $m, $d, $y ) = ( $part[1], $part[0], $part[2] );
1750 }
1751  
1752 # Now validate the day of month ...
1753 29 ▶ if ( $m > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m > 0) 26 3 29
1754 26 DBUG_PRINT ("INFO", "Validating if using %s format.", $lbls[$id]);
1755 26 $y = make_it_a_4_digit_year ( $y );
1756  
1757 26 my $max = $days_in_months[$m];
1758 26 ▶ if ( $m == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m == 2) 0 26 26
1759 0 my $leap = _is_leap_year ($y);
1760 0 ▶ ++$max if ( $leap );
Branch: 1 branch
BranchTrueFalseTotal
if $leap 0 0 0
1761 }
1762  
1763 26 ▶ if ( $d <= $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= $max) 26 0 26
1764 26 ( $year, $month, $day ) = ( $y, $m, $d );
1765 26 last;
1766 }
1767 }
1768 }
1769 }
1770  
1771 26 DBUG_RETURN ( $year, $month, $day );
1772 }
1773  
1774  
1775 # ==============================================================
1776  
1777 =item (\@months, \@weekdays) = init_special_date_arrays ( $lang[, $mode[, $wok[, $wide]]] );
1778  
1779 Prefers getting the date names from I<Date::Manip::Lang::${lang}> for the
1780 I<Advanced::Config> special date variables. But if the language isn't supported
1781 by that module it tries I<Date::Language::${lang}> instead. This is because
1782 the 1st module is more consistent.
1783  
1784 If the I<$lang> doesn't exist, then it returns the arrays for the last valid
1785 language.
1786  
1787 If I<$wok> is set to a non-zero value, it will print warnings to your screen if
1788 there were issues in changing the language used.
1789  
1790 I<$mode> tells how to return the various arrays:
1791  
1792 1 - Abbreviated month/weekday names in the requested language.
1793 2 - Full month/weekday names in the requested language.
1794 Any other value and it will return the numeric values. (default)
1795  
1796 For @months, indexes are 0..11, with 0 representing January.
1797  
1798 For @weekdays, indexes are 0..6, with 0 representing Sunday.
1799  
1800 Languages like 'Greek' that rely on I<Wide Chars> require the I<$wide> flag set to
1801 true. Otherwise that language is disabled.
1802  
1803 =cut
1804  
1805 sub init_special_date_arrays
1806 167 ▶{
Subroutine init_special_date_arrays: called CC=19 SCAR=31.2
Pod documented
1807 167 DBUG_ENTER_FUNC ( @_ );
1808 167 my $lang = shift;
1809 167 ▶ my $mode = shift || 0; # Default to numeric arrays ...
Condition100%2/2
shift() || 0
l!l
21146
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1810 167 ▶ my $warn_ok = shift || 0;
Condition100%2/2
shift() || 0
l!l
12155
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1811 167 ▶ my $allow_wide = shift || 0;
Condition100%2/2
shift() || 0
l!l
6161
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1812  
1813 167 my @months = ( "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" );
1814 167 my @week_days = ( "1", "2", "3", "4", "5", "6", "7" );
1815  
1816 167 ▶ my $numbers = ($mode != 1 && $mode != 2 );
Condition100%3/3
$mode != 1 && $mode != 2
!ll&&!rl&&r
810149
MC/DC100%2/2
$mode != 1 && $mode != 2
$mode != 1 $mode != 2
Truth table100%3/3
A && B
A= $mode != 1B= $mode != 2
ABresult
0X0
100
111
1817  
1818 167 my ( $lang_ref, $manip_ref );
1819  
1820 167 ▶ if ( defined $lang ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lang) 161 6 167
1821 161 ($manip_ref, $lang_ref) = _select_language ($lang, $warn_ok, $allow_wide);
1822  
1823 161 ▶ unless ( $lang_ref || $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lang_ref or $manip_ref) 0 161 161
Condition33%1/3
$lang_ref or $manip_ref
l!l&&r!l&&!r
16100
MC/DC0%0/2
$lang_ref or $manip_ref
$lang_ref $manip_ref
Truth table33%1/3
A or B
A= $lang_refB= $manip_ref
ABresult
1X1
011
000
1824 0 $lang = undef; # So it will enter the early out if block ...
1825 }
1826 }
1827  
1828 167 ▶ if ( (! defined $lang) || lc($lang) eq lc($prev_array_lang) || $numbers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $lang or lc $lang eq lc $prev_array_lang or $numbers) 165 2 167
Condition100%6/6
not defined $lang or lc $lang eq lc $prev_array_lang or $numbers
l!l&&r!l&&!r
16322
not defined $lang or lc $lang eq lc $prev_array_lang
l!l&&r!l&&!r
61574
MC/DC100%3/3
not defined $lang or lc $lang eq lc $prev_array_lang or $numbers
not defined $lang lc $lang eq lc $prev_array_lang $numbers
Truth table100%4/4
not(A) or B or C
A= not defined $langB= lc $lang eq lc $prev_array_langC= $numbers
ABCresult
1XX1
01X1
0011
0000
1829 165 ▶ if ( $mode == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode == 1) { } 6 159 165
elsif ($mode == 2) { } 10 149 159
1830 6 @months = @gMoYs; # Abrevited month names ...
1831 6 @week_days = @gDoWs; # Abrevited week names ...
1832 } elsif ( $mode == 2 ) {
1833 10 @months = @gMoY; # Full month names ...
1834 10 @week_days = @gDoW; # Full week names ...
1835 }
1836 165 return DBUG_RETURN ( \@months, \@week_days );
1837 }
1838  
1839 2 my ($MoY_ref, $MoYs_ref, $Dsuf_ref, $DoW_ref, $DoWs_ref);
1840  
1841 2 DBUG_PRINT ("INFO", "Manip: %s, Lang: %s", $manip_ref, $lang_ref);
1842 2 ▶ if ( $manip_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($manip_ref) 0 2 2
1843 0 my ( $u1, $u2, $u3 ); # Unused placeholders.
1844 0 ($u1, $u2, $u3, $MoY_ref, $MoYs_ref, $Dsuf_ref, $DoW_ref, $DoWs_ref) =
1845 _swap_manip_language_common ($manip_ref, $warn_ok, $allow_wide );
1846 0 $lang = $manip_ref->{Language};
1847  
1848 0 ▶ if ( $u1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u1) { } 0 0 0
1849 0 $lang_ref = undef; # Skip lang_ref lookup if successsful ...
1850 } else {
1851 0 $lang_ref = $date_language_installed_languages{lc($lang)};
1852 }
1853 }
1854  
1855 2 ▶ if ( $lang_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang_ref) 2 0 2
1856 2 ($MoY_ref, $MoYs_ref, $Dsuf_ref, $DoW_ref, $DoWs_ref) =
1857 _swap_lang_common ( $lang_ref, $warn_ok, $allow_wide );
1858 2 $lang = $lang_ref->{Language};
1859 }
1860  
1861  
1862 # If the new language was valid, update the global variables ...
1863 2 ▶ if ( $MoY_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MoY_ref) 2 0 2
1864 2 $prev_array_lang = $lang;
1865 2 @gMoY = @{$MoY_ref};
1866 2 @gMoYs = map { uc($_) } @{$MoYs_ref};
1867 2 @gDoW = @{$DoW_ref};
1868 2 @gDoWs = map { uc($_) } @{$DoWs_ref};
1869 2 @gDsuf = @{$Dsuf_ref};
1870  
1871 2 DBUG_PRINT ( "LANGUAGE", "%s\n%s\n%s\n%s\n%s",
1872 join (", ", @gMoY), join (", ", @gMoYs),
1873 join (", ", @gDoW), join (", ", @gDoWs),
1874 join (", ", @gDsuf)
1875 );
1876 }
1877  
1878 # Numeric handled earlier ...
1879 2 ▶ if ( $mode == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode == 1) { } 2 0 2
elsif ($mode == 2) { } 0 0 0
1880 2 @months = @gMoYs; # Abrevited month names ...
1881 2 @week_days = @gDoWs; # Abrevited week names ...
1882 } elsif ( $mode == 2 ) {
1883 0 @months = @gMoY; # Full month names ...
1884 0 @week_days = @gDoW; # Full week names ...
1885 }
1886  
1887 2 DBUG_RETURN ( \@months, \@week_days );
1888 }
1889  
1890 # ==============================================================
1891  
1892 sub _is_leap_year
1893 26518 ▶{
Subroutine _is_leap_year: called CC=4 SCAR=13.9
1894 26518 my $year = shift;
1895 26518 ▶ my $leap = ($year % 4 == 0) && ($year % 100 != 0 || $year % 400 == 0);
Condition100%6/6
$year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)
!ll&&!rl&&r
196592176642
$year % 100 != 0 or $year % 400 == 0
l!l&&r!l&&!r
6479163217
MC/DC100%3/3
$year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)
$year % 4 == 0 $year % 100 != 0 $year % 400 == 0
Truth table100%4/4
A && B or C
A= $year % 4 == 0B= $year % 100 != 0C= $year % 400 == 0
ABCresult
0XX0
1000
11X1
1011
1896 26518 ▶ return ($leap ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 6642 19876 26518
1897 }
1898  
1899 # ==============================================================
1900  
1901 # Validate the input date.
1902 sub _validate_date_str
1903 840 ▶{
Subroutine _validate_date_str: called CC=8 SCAR=22.9
1904 840 DBUG_ENTER_FUNC ( @_ );
1905 840 my $date_str = shift;
1906  
1907 840 my ($year, $mon, $day);
1908 840 ▶ if ( defined $date_str && $date_str =~ m/^(\d+)-(\d+)-(\d+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date_str and $date_str =~ /^(\d+)-(\d+)-(\d+)$/) { } 836 4 840
Condition66%2/3
defined $date_str and $date_str =~ /^(\d+)-(\d+)-(\d+)$/
!ll&&!rl&&r
04836
MC/DC50%1/2
defined $date_str and $date_str =~ /^(\d+)-(\d+)-(\d+)$/
defined $date_str $date_str =~ /^(\d+)-(\d+)-(\d+)$/
Truth table66%2/3
A and B
A= defined $date_strB= $date_str =~ /^(\d+)-(\d+)-(\d+)$/
ABresult
0X0
100
111
1909 836 ($year, $mon, $day) = ($1, $2, $3);
1910 836 my $leap = _is_leap_year ($year);
1911 836 ▶ local $days_in_months[2] = $leap ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 285 551 836
1912 836 ▶ unless ( 1 <= $mon && $mon <= 12 &&
Branch: 1 branch
BranchTrueFalseTotal
unless (1 <= $mon and $mon <= 12 and 1 <= $day and $day <= $days_in_months[$mon]) 0 836 836
Condition33%3/9
1 <= $mon and $mon <= 12 and 1 <= $day and $day <= $days_in_months[$mon]
!ll&&!rl&&r
00836
1 <= $mon and $mon <= 12 and 1 <= $day
!ll&&!rl&&r
00836
1 <= $mon and $mon <= 12
!ll&&!rl&&r
00836
MC/DC0%0/4
1 <= $mon and $mon <= 12 and 1 <= $day and $day <= $days_in_months[$mon]
1 <= $mon $mon <= 12 1 <= $day $day <= $days_in_months[$mon]
Truth table20%1/5
A and B and C and D
A= 1 <= $monB= $mon <= 12C= 1 <= $dayD= $day <= $days_in_months[$mon]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1913 1 <= $day && $day <= $days_in_months[$mon] ) {
1914 0 return DBUG_RETURN ( undef, undef, undef );
1915 }
1916 } else {
1917 4 return DBUG_RETURN ( undef, undef, undef );
1918 }
1919  
1920 836 DBUG_RETURN ( $year, $mon, $day );
1921 }
1922  
1923 # ==============================================================
1924  
1925 =item $bool = is_leap_year ( $year );
1926  
1927 Returns B<1> if I<$year> is a Leap Year, else B<0> if it isn't.
1928  
1929 =cut
1930  
1931 sub is_leap_year
1932 134 ▶{
Subroutine is_leap_year: called CC=1 SCAR=0.0
Pod documented
1933 134 DBUG_ENTER_FUNC ( @_ );
1934 134 DBUG_RETURN ( _is_leap_year (@_) );
1935 }
1936  
1937 # ==============================================================
1938  
1939 =item $hyd = calc_hundred_year_date ( $date_str );
1940  
1941 Takes a date string in B<YYYY-MM-DD> format and returns the number of days since
1942 B<1899-12-31>. (Which is HYD B<0>.) It should be compatible with DB2's data
1943 type of the same name. Something like this function is needed if you wish to be
1944 able to do date math.
1945  
1946 For example:
1947  
1948 1 : 2026-01-01 - 2025-12-30 = 2 days.
1949 2 : 2025-12-31 + 10 = 2026-01-10.
1950 2 : 2025-12-31 - 2 = 2025-12-29.
1951  
1952 If the given date string is invalid it will return B<undef>.
1953  
1954 =cut
1955  
1956 sub calc_hundred_year_date
1957 190 ▶{
Subroutine calc_hundred_year_date: called CC=7 SCAR=19.5
Pod documented
1958 190 DBUG_ENTER_FUNC ( @_ );
1959 190 my $date_str = shift;
1960  
1961 # Validate the input date.
1962 190 my ($end_year, $month, $day) = _validate_date_str ($date_str);
1963 190 ▶ unless (defined $end_year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $end_year) 0 190 190
1964 0 return DBUG_RETURN ( undef );
1965 }
1966  
1967 190 my $hyd = 0;
1968 190 my $start_year = 1899;
1969  
1970 190 ▶ if ( $end_year > $start_year ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_year > $start_year) { } 102 88 190
1971 102 ▶ for (my $year = $start_year + 1; $year < $end_year; ++$year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year < $end_year) 10318 102 10420
1972 10318 my $leap = _is_leap_year ($year);
1973 10318 ▶ $hyd += $leap ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 2510 7808 10318
1974 }
1975 102 $hyd += calc_day_of_year ($date_str, 0);
1976  
1977 } else { # $hyd <= 0 ...
1978 88 ▶ for (my $year = $start_year; $year > $end_year; --$year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year > $end_year) 6226 88 6314
1979 6226 my $leap = _is_leap_year ($year);
1980 6226 ▶ $hyd -= $leap ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 1532 4694 6226
1981 }
1982 88 $hyd -= calc_day_of_year ($date_str, 1);
1983 }
1984  
1985 190 DBUG_RETURN ($hyd);
1986 }
1987  
1988 # ==============================================================
1989  
1990 =item $dow = calc_day_of_week ( $date_str );
1991  
1992 Takes a date string in B<YYYY-MM-DD> format and returns the day of the week it
1993 falls on. It returns a value between B<0> and B<6> for Sunday to Saturday.
1994  
1995 If the given date is invalid it will return B<undef>.
1996  
1997 =item $dow = calc_day_of_week ( $hyd );
1998  
1999 It takes an integer as a Hundred Year Date and returns the day of the week it
2000 falls on. It returns a value between B<0> and B<6> for Sunday to Saturday.
2001  
2002 If the given hyd is not an integer it will return B<undef>.
2003  
2004 =cut
2005  
2006 sub calc_day_of_week
2007 187 ▶{
Subroutine calc_day_of_week: called CC=4 SCAR=14.0
Pod documented
2008 187 DBUG_ENTER_FUNC ( @_ );
2009 187 my $date_str = shift; # or a HYD ...
2010  
2011 187 my $hyd;
2012 187 ▶ if ( defined $date_str && $date_str =~ m/^[-]?\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date_str and $date_str =~ /^[-]?\d+$/) { } 89 98 187
Condition66%2/3
defined $date_str and $date_str =~ /^[-]?\d+$/
!ll&&!rl&&r
09889
MC/DC50%1/2
defined $date_str and $date_str =~ /^[-]?\d+$/
defined $date_str $date_str =~ /^[-]?\d+$/
Truth table66%2/3
A and B
A= defined $date_strB= $date_str =~ /^[-]?\d+$/
ABresult
0X0
100
111
2013 89 $hyd = $date_str;
2014 } else {
2015 98 $hyd = calc_hundred_year_date ( $date_str );
2016 }
2017  
2018 187 ▶ unless (defined $hyd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hyd) 0 187 187
2019 0 return DBUG_RETURN ( undef );
2020 }
2021  
2022 187 my $start_dow = 0; # $hyd 0, 1899-12-31, falls on a Sunday.
2023  
2024 187 my $dow = ($hyd + $start_dow) % 7;
2025  
2026 187 DBUG_RETURN ($dow);
2027 }
2028  
2029 # ==============================================================
2030  
2031 =item $date_str = convert_hyd_to_date_str ( $hyd );
2032  
2033 It takes an integer as a Hundred Year Date and converts it into a date string
2034 in the format of B<YYYY-MM-DD> and returns it.
2035  
2036 If the given hyd is not an integer it will return B<undef>.
2037  
2038 =cut
2039  
2040 sub convert_hyd_to_date_str
2041 89 ▶{
Subroutine convert_hyd_to_date_str: called CC=16 SCAR=27.8
Pod documented
2042 89 DBUG_ENTER_FUNC ( @_ );
2043 89 my $target_hyd = shift;
2044  
2045 89 ▶ unless ( defined $target_hyd && $target_hyd =~ m/^[-]?\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target_hyd and $target_hyd =~ /^[-]?\d+$/) 0 89 89
Condition33%1/3
defined $target_hyd and $target_hyd =~ /^[-]?\d+$/
!ll&&!rl&&r
0089
MC/DC0%0/2
defined $target_hyd and $target_hyd =~ /^[-]?\d+$/
defined $target_hyd $target_hyd =~ /^[-]?\d+$/
Truth table33%1/3
A and B
A= defined $target_hydB= $target_hyd =~ /^[-]?\d+$/
ABresult
0X0
100
111
2046 0 return DBUG_RETURN ( undef );
2047 }
2048  
2049 89 my $date_str;
2050 89 my $start_year = 1899; # HYD of 0 is 1899-12-31
2051 89 my $hyd_total = 0;
2052 89 my $days = 0;
2053 89 my ($leap, $year);
2054  
2055 89 ▶ if ( $target_hyd > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_hyd > 0) { } 45 44 89
2056 45 for ($year = $start_year + 1; 1==1; ++$year) {
2057 5204 $leap = _is_leap_year ($year);
2058 5204 ▶ $days = $leap ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 1271 3933 5204
2059 5204 ▶ if ( ($hyd_total + $days) >= $target_hyd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hyd_total + $days >= $target_hyd) 45 5159 5204
2060 45 last;
2061 }
2062 5159 $hyd_total += $days;
2063 }
2064 45 ▶ local $days_in_months[2] = $leap ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 16 29 45
2065 45 for (1..12) {
2066 274 $days = $days_in_months[$_];
2067 274 ▶ if ( ($hyd_total + $days) >= $target_hyd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hyd_total + $days >= $target_hyd) 45 229 274
2068 45 my $diff = $target_hyd - $hyd_total;
2069 45 $date_str = sprintf ("%04d-%02d-%02d", $year, $_, $diff);
2070 45 last;
2071 }
2072 229 $hyd_total += $days;
2073 }
2074  
2075 } else { # $target_hyd <= 0.
2076 44 for ($year = $start_year; 1==1; --$year) {
2077 3155 $leap = _is_leap_year ($year);
2078 3155 ▶ $days = $leap ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 782 2373 3155
2079 3155 ▶ if ( ($hyd_total - $days) <= $target_hyd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hyd_total - $days <= $target_hyd) 44 3111 3155
2080 44 last;
2081 }
2082 3111 $hyd_total -= $days;
2083 }
2084 44 ▶ local $days_in_months[2] = $leap ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 17 27 44
2085 44 for (reverse 1..12) {
2086 292 $days = $days_in_months[$_];
2087 292 ▶ if ( ($hyd_total - $days) <= $target_hyd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hyd_total - $days <= $target_hyd) 44 248 292
2088 44 my $diff = $target_hyd - $hyd_total;
2089 44 my $ans = $diff + $days;
2090  
2091 44 DBUG_PRINT("-FINAL-", "Target: %d, Current: %d, Diff: %d, Year: %d/%02d, Day: %02d", $target_hyd, $hyd_total, $diff, $year, $_, $ans);
2092  
2093 44 ▶ if ($ans) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ans) { } 29 15 44
elsif ($_ == 1) { } 2 13 15
2094 29 $date_str = sprintf ("%04d-%02d-%02d", $year, $_, $ans);
2095 } elsif ( $_ == 1 ) {
2096 2 $ans = $days_in_months[12];
2097 2 $date_str = sprintf ("%04d-%02d-%02d", $year - 1, 12, $ans);
2098 } else {
2099 13 $ans = $days_in_months[$_ - 1];
2100 13 $date_str = sprintf ("%04d-%02d-%02d", $year, $_ - 1, $ans);
2101 }
2102 44 last;
2103 }
2104 248 $hyd_total -= $days;
2105  
2106 248 DBUG_PRINT("MONTHLY", "Target: %d, Current: %d, Year: %d/%02d", $target_hyd, $hyd_total, $year, $_);
2107 }
2108 }
2109  
2110 89 DBUG_RETURN ($date_str);
2111 }
2112  
2113 # ==============================================================
2114  
2115 =item $doy = calc_day_of_year ( $date_str[, $remainder_flag] );
2116  
2117 Takes a date string in B<YYYY-MM-DD> format and returns the number of days since
2118 the begining of the year. With January 1st being day B<1>.
2119  
2120 If the remainder_flag is set to a no-zero value, it returns the number of days
2121 left in the year. With December 31st being B<0>.
2122  
2123 If the given date is invalid it will return B<undef>.
2124  
2125 =cut
2126  
2127 sub calc_day_of_year
2128 546 ▶{
Subroutine calc_day_of_year: called CC=7 SCAR=19.5
Pod documented
2129 546 DBUG_ENTER_FUNC ( @_ );
2130 546 my $date_str = shift;
2131 546 ▶ my $remainder_flag = shift || 0;
Condition100%2/2
shift() || 0
l!l
264282
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
2132  
2133 # Validate the input date.
2134 546 my ($year, $month, $day) = _validate_date_str ($date_str);
2135 546 ▶ unless (defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 546 546
2136 0 return DBUG_RETURN ( undef );
2137 }
2138  
2139 546 my $leap = _is_leap_year ($year);
2140 546 ▶ local $days_in_months[2] = $leap ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 192 354 546
2141  
2142 546 my $doy = 0;
2143 546 ▶ for (my $m = 0; $m < $month; ++$m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m < $month) 4378 546 4924
2144 4378 $doy += $days_in_months[$m];
2145 }
2146 546 $doy += $day;
2147  
2148 546 ▶ if ($remainder_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder_flag) 264 282 546
2149 264 ▶ my $total_days_in_year = $leap ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 96 168 264
2150 264 $doy = $total_days_in_year - $doy;
2151 }
2152  
2153 546 DBUG_RETURN ($doy);
2154 }
2155  
2156 # ==============================================================
2157  
2158 =item $date_str = adjust_date_str ( $date_str, $years, $months );
2159  
2160 Takes a date string in B<YYYY-MM-DD> format and adjusts it by the given number
2161 of months and years. It returns the new date in B<YYYY-MM-Dd> format.
2162  
2163 It does its best to preserve the day of month, but if it would exceed the number
2164 of days in a month, it will truncate to the end of month. Not round to the next
2165 month.
2166  
2167 Returns I<undef> if passed bad arguments.
2168  
2169 =cut
2170  
2171 sub adjust_date_str
2172 96 ▶{
Subroutine adjust_date_str: called CC=13 SCAR=25.9
Pod documented
2173 96 DBUG_ENTER_FUNC ( @_ );
2174 96 my $date_str = shift;
2175 96 ▶ my $adj_years = shift || 0;
Condition100%2/2
shift() || 0
l!l
2967
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
2176 96 ▶ my $adj_months = shift || 0;
Condition100%2/2
shift() || 0
l!l
7818
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
2177  
2178 # Validate the input date.
2179 96 my ($year, $month, $day) = _validate_date_str ($date_str);
2180 96 ▶ unless (defined $year &&
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year and $adj_years =~ /^[-]?\d+$/ and $adj_months =~ /^[-]?\d+$/) 0 96 96
Condition33%2/6
defined $year and $adj_years =~ /^[-]?\d+$/ and $adj_months =~ /^[-]?\d+$/
!ll&&!rl&&r
0096
defined $year and $adj_years =~ /^[-]?\d+$/
!ll&&!rl&&r
0096
MC/DC0%0/3
defined $year and $adj_years =~ /^[-]?\d+$/ and $adj_months =~ /^[-]?\d+$/
defined $year $adj_years =~ /^[-]?\d+$/ $adj_months =~ /^[-]?\d+$/
Truth table25%1/4
A and B and C
A= defined $yearB= $adj_years =~ /^[-]?\d+$/C= $adj_months =~ /^[-]?\d+$/
ABCresult
0XX0
10X0
1100
1111
2181 $adj_years =~ m/^[-]?\d+$/ && $adj_months =~ m/^[-]?\d+$/) {
2182 0 return DBUG_RETURN ( undef );
2183 }
2184  
2185 # Adjust by month ...
2186 96 ▶ if ( $adj_months >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($adj_months >= 0) { } 65 31 96
2187 65 foreach (1..${adj_months}) {
2188 284 ▶ if ( $month == 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($month == 12) { } 37 247 284
2189 37 $month = 1;
2190 37 ++$adj_years;
2191 } else {
2192 247 ++$month;
2193 }
2194 }
2195 } else {
2196 31 foreach (1..-${adj_months}) {
2197 358 ▶ if ( $month == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($month == 1) { } 17 341 358
2198 17 $month = 12;
2199 17 --$adj_years;
2200 } else {
2201 341 --$month;
2202 }
2203 }
2204 }
2205  
2206 # Adjust the years ...
2207 96 $year += $adj_years;
2208  
2209 # Build the returned date ...
2210 96 my $leap = _is_leap_year ($year);
2211 96 ▶ local $days_in_months[2] = $leap ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$leap ? : 38 58 96
2212 96 my $d = $days_in_months[$month];
2213  
2214 96 ▶ $date_str = sprintf ("%04d-%02d-%02d", $year, $month,
Branch: 1 branch
BranchTrueFalseTotal
$day <= $d ? : 70 26 96
2215 ($day <= $d) ? $day : $d);
2216  
2217 96 DBUG_RETURN ($date_str);
2218 }
2219  
2220 # ==============================================================
2221  
2222 =back
2223  
2224 =head1 SOME EXAMPLE DATES
2225  
2226 Here are some sample date strings in B<English> that this module can parse.
2227 All for Christmas 2017. This is not a complete list of available date formats
2228 supported. But should hopefully give you a starting point of what is possible.
2229 Remember that if a date string contains extra info around the date part of it,
2230 that extra information is thrown away.
2231  
2232 S<12/25/2017>, B<S<Mon Dec 25th 2017 at 09:00>>, S<Mon 2017/12/25>, B<S<2017-12-25>>,
2233 S<Monday December 25th, 2017 at 09:00>, B<S<12.25.2017>>, S<25-DEC-2017>,
2234 B<S<25-DECEMBER-2017>>, S<20171225>, B<S<12252017>>,
2235 S<Mon dec. 25th 00:00:00 2017>, B<S<2017 12 25 mon>>.
2236  
2237 Most of the above examples will also work with 2-digit years as well.
2238  
2239 And just to remind you that other languages are supported if L<Date::Language>
2240 is installed, here's a date in Spanish that would be legal after
2241 S<swap_language("Spanish")> was called.
2242  
2243 =over 4
2244  
2245 B<S<Lun Diciembre 25to 2017 18:05>>.
2246  
2247 =back
2248  
2249 =head1 COPYRIGHT
2250  
2251 Copyright (c) 2018 - 2026 Curtis Leach. All rights reserved.
2252  
2253 This program is free software. You can redistribute it and/or modify it under
2254 the same terms as Perl itself.
2255  
2256 =head1 SEE ALSO
2257  
2258 L<Advanced::Config> - The main user of this module. It defines the Config object.
2259  
2260 L<Advanced::Config::Options> - Handles the configuration of the Config module.
2261  
2262 L<Advanced::Config::Reader> - Handles the parsing of the config file.
2263  
2264 L<Advanced::Config::Examples> - Provides some sample config files and commentary.
2265  
2266 L<Date::Language> - Provides foreign language support.
2267  
2268 L<Date::Manip> - Provides additional foreign language support.
2269  
2270 =cut
2271  
2272 # ==============================================================
2273 #required if module is included w/ require command;
2274 29 1;
2275  
↑ Summary Config/Options.pm »