| 1 | =for gpg | ||||||||||||||||||||||||||||||||||||||||||
| 2 | -----BEGIN PGP SIGNED MESSAGE----- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | Hash: SHA1 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Time::Normalize - Convert time and date values into standardized components. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | This is version 0.09 of Time::Normalize, April 23, 2014. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | package Time::Normalize; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | $Time::Normalize::VERSION = '0.09'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | use vars qw/@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | @ISA = qw/Exporter/; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | @EXPORT = qw/normalize_hms normalize_time normalize_ymd normalize_gmtime | |||||||||||||||||||||||||||||||||||||||||
| 24 | normalize_month normalize_year normalize_ym | ||||||||||||||||||||||||||||||||||||||||||
| 25 | normalize_ymd3 normalize_ym3 | ||||||||||||||||||||||||||||||||||||||||||
| 26 | normalize_ymdhms normalize_rct | ||||||||||||||||||||||||||||||||||||||||||
| 27 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | @EXPORT_OK = (@EXPORT, qw(mon_name mon_abbr day_name day_abbr days_in is_leap)); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Is POSIX available? | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | eval {require POSIX }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | my $have_posix = $@? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Delay loading Carp until needed | ||||||||||||||||||||||||||||||||||||||||||
| 36 | sub _croak | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 91 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 91 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 91 | goto &Carp::croak; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Most error messages in this module look very similar. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # This standardizes them: | ||||||||||||||||||||||||||||||||||||||||||
| 44 | sub _bad | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 61 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bad: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 61 | my ($what, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 61 | ▶ | $value = '(undefined)' if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 61 | _croak qq{Time::Normalize: Invalid $what: "$value"}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Current locale. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | my $locale; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Month names; Month names abbrs, Weekday names, Weekday name abbrs. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # *All Mixed-Case!* | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | our (@Mon_Name, @Mon_Abbr, @Day_Name, @Day_Abbr); | |||||||||||||||||||||||||||||||||||||||||
| 57 | # Lookup: string-month => numeric-month (also string-day => numeric-day) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | our %number_of; | |||||||||||||||||||||||||||||||||||||||||
| 59 | # We need english-only names to parse R::C::t's 'mail' format. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | my $mail_month_number; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | our $use_mail_months; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Current year and century. Used for guessing century of two-digit years. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | my $current_year = (localtime)[5] + 1900; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | my ($current_century, $current_yy) = $current_year =~ /(\d\d)(\d\d)/; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # Number of days in each (1-based) month (except February). | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | my @num_days_in = qw(0 31 29 31 30 31 30 31 31 30 31 30 31); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | sub days_in | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 152 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
days_in: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 152 | ▶ | _croak "Too few arguments to days_in" if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 151 | ▶ | _croak "Too many arguments to days_in" if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 150 | my ($m,$y) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 150 | ▶ | _croak qq{Non-integer month "$m" for days_in} if $m !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 149 | ▶ | _bad('month', $m) if $m < 1 || $m > 12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$m < 1 or $m > 12
MC/DC0%0/2
$m < 1 or $m > 12
$m < 1
$m > 12
Truth table33%1/3
A or B
A= $m < 1B= $m > 12
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 149 | ▶ | return $num_days_in[$m] if $m != 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # February | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | ▶ | return is_leap($y)? 29 : 28; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # Is a leap year? | ||||||||||||||||||||||||||||||||||||||||||
| 84 | sub is_leap | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_leap: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 24 | ▶ | _croak "Too few arguments to is_leap" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 23 | ▶ | _croak "Too many arguments to is_leap" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 22 | my $year = shift; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 22 | ▶ | return !($year%4) && ( ($year%100) || !($year%400) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
!($year % 4) && ($year % 100 || !($year % 400))
$year % 100 or not $year % 400
MC/DC100%3/3
!($year % 4) && ($year % 100 || !($year % 400))
!($year % 4)
$year % 100
not $year % 400
Truth table100%4/4
not(A) && B or not(C)
A= !($year % 4)B= $year % 100C= not $year % 400
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Quickie function to pad a number with a leading 0. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 486 | ▶ | sub _lead0 { $_[0] > 9? $_[0]+0 : '0'.($_[0]+0)} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lead0: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # Compute day of week, using Zeller's congruence | ||||||||||||||||||||||||||||||||||||||||||
| 96 | sub _dow | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 95 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dow: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 95 | my ($Y, $M, $D) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 95 | $M -= 2; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 95 | ▶ | if ($M < 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 17 | $M += 12; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 17 | $Y--; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 95 | my $C = int($Y/100); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 95 | $Y %= 100; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 95 | return (int((26*$M - 2)/10) + $D + $Y + int($Y/4) + int($C/4) - 2*$C) % 7; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # Internal function to initialize locale info. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | sub _setup_locale | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 392 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_locale: called CC=9 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | # Do nothing if locale has not changed since %names was set up. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 392 | my $locale_in_use; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 392 | ▶ | $locale_in_use = $have_posix? POSIX::setlocale(POSIX::LC_TIME()) : 'no posix; use defaults'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 392 | ▶ | $locale_in_use = q{} if !defined $locale_in_use; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # No changes needed | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 392 | ▶ | return if defined $locale && $locale eq $locale_in_use; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $locale and $locale eq $locale_in_use
MC/DC50%1/2
defined $locale and $locale eq $locale_in_use
defined $locale
$locale eq $locale_in_use
Truth table66%2/3
A and B
A= defined $localeB= $locale eq $locale_in_use
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | $locale = $locale_in_use; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | require I18N::Langinfo; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | I18N::Langinfo->import ('langinfo'); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | @Mon_Name = map langinfo($_), ( | |||||||||||||||||||||||||||||||||||||||||
| 131 | I18N::Langinfo::MON_1(), | ||||||||||||||||||||||||||||||||||||||||||
| 132 | I18N::Langinfo::MON_2(), | ||||||||||||||||||||||||||||||||||||||||||
| 133 | I18N::Langinfo::MON_3(), | ||||||||||||||||||||||||||||||||||||||||||
| 134 | I18N::Langinfo::MON_4(), | ||||||||||||||||||||||||||||||||||||||||||
| 135 | I18N::Langinfo::MON_5(), | ||||||||||||||||||||||||||||||||||||||||||
| 136 | I18N::Langinfo::MON_6(), | ||||||||||||||||||||||||||||||||||||||||||
| 137 | I18N::Langinfo::MON_7(), | ||||||||||||||||||||||||||||||||||||||||||
| 138 | I18N::Langinfo::MON_8(), | ||||||||||||||||||||||||||||||||||||||||||
| 139 | I18N::Langinfo::MON_9(), | ||||||||||||||||||||||||||||||||||||||||||
| 140 | I18N::Langinfo::MON_10(), | ||||||||||||||||||||||||||||||||||||||||||
| 141 | I18N::Langinfo::MON_11(), | ||||||||||||||||||||||||||||||||||||||||||
| 142 | I18N::Langinfo::MON_12(), | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | @Mon_Abbr = map langinfo($_), ( | |||||||||||||||||||||||||||||||||||||||||
| 145 | I18N::Langinfo::ABMON_1(), | ||||||||||||||||||||||||||||||||||||||||||
| 146 | I18N::Langinfo::ABMON_2(), | ||||||||||||||||||||||||||||||||||||||||||
| 147 | I18N::Langinfo::ABMON_3(), | ||||||||||||||||||||||||||||||||||||||||||
| 148 | I18N::Langinfo::ABMON_4(), | ||||||||||||||||||||||||||||||||||||||||||
| 149 | I18N::Langinfo::ABMON_5(), | ||||||||||||||||||||||||||||||||||||||||||
| 150 | I18N::Langinfo::ABMON_6(), | ||||||||||||||||||||||||||||||||||||||||||
| 151 | I18N::Langinfo::ABMON_7(), | ||||||||||||||||||||||||||||||||||||||||||
| 152 | I18N::Langinfo::ABMON_8(), | ||||||||||||||||||||||||||||||||||||||||||
| 153 | I18N::Langinfo::ABMON_9(), | ||||||||||||||||||||||||||||||||||||||||||
| 154 | I18N::Langinfo::ABMON_10(), | ||||||||||||||||||||||||||||||||||||||||||
| 155 | I18N::Langinfo::ABMON_11(), | ||||||||||||||||||||||||||||||||||||||||||
| 156 | I18N::Langinfo::ABMON_12(), | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | @Day_Name = map langinfo($_), ( | |||||||||||||||||||||||||||||||||||||||||
| 159 | I18N::Langinfo::DAY_1(), | ||||||||||||||||||||||||||||||||||||||||||
| 160 | I18N::Langinfo::DAY_2(), | ||||||||||||||||||||||||||||||||||||||||||
| 161 | I18N::Langinfo::DAY_3(), | ||||||||||||||||||||||||||||||||||||||||||
| 162 | I18N::Langinfo::DAY_4(), | ||||||||||||||||||||||||||||||||||||||||||
| 163 | I18N::Langinfo::DAY_5(), | ||||||||||||||||||||||||||||||||||||||||||
| 164 | I18N::Langinfo::DAY_6(), | ||||||||||||||||||||||||||||||||||||||||||
| 165 | I18N::Langinfo::DAY_7(), | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | @Day_Abbr = map langinfo($_), ( | |||||||||||||||||||||||||||||||||||||||||
| 168 | I18N::Langinfo::ABDAY_1(), | ||||||||||||||||||||||||||||||||||||||||||
| 169 | I18N::Langinfo::ABDAY_2(), | ||||||||||||||||||||||||||||||||||||||||||
| 170 | I18N::Langinfo::ABDAY_3(), | ||||||||||||||||||||||||||||||||||||||||||
| 171 | I18N::Langinfo::ABDAY_4(), | ||||||||||||||||||||||||||||||||||||||||||
| 172 | I18N::Langinfo::ABDAY_5(), | ||||||||||||||||||||||||||||||||||||||||||
| 173 | I18N::Langinfo::ABDAY_6(), | ||||||||||||||||||||||||||||||||||||||||||
| 174 | I18N::Langinfo::ABDAY_7(), | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # make the month arrays 1-based: | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | for (\@Mon_Name, \@Mon_Abbr) | |||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 16 | unshift @$_, 'n/a'; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | ▶ | if ($@) # If internationalization didn't work for some reason, go with English. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | @Mon_Name = qw(n/a January February March April May June July August September October November December); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | @Mon_Abbr = map substr($_,0,3), @Mon_Name; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | @Day_Name = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | @Day_Abbr = map substr($_,0,3), @Day_Name; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | %number_of = (); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | for (1..12) | |||||||||||||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 96 | $number_of{uc $Mon_Name[$_]} = $number_of{uc $Mon_Abbr[$_]} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # This module doesn't use reverse DOW lookups, but someone might want it. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | for (0..6) | |||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 56 | $number_of{uc $Day_Name[$_]} = $number_of{uc $Day_Abbr[$_]} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | sub _init_mail_months | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_mail_months: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | my @abbrs = qw(n/a Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | %$mail_month_number = (); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | for (1..12) | |||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | $mail_month_number->{uc $abbrs[$_]} = $_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | my %ap_from_ampm = (a => 'a', am => 'a', 'a.m.' => 'a', p => 'p', pm => 'p', 'p.m.' => 'p'); | |||||||||||||||||||||||||||||||||||||||||
| 213 | sub normalize_hms | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 73 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_hms: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 73 | ▶ | _croak "Too few arguments to normalize_hms" if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 72 | ▶ | _croak "Too many arguments to normalize_hms" if @_ > 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 71 | my ($inh, $inm, $ins, $ampm) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 71 | my ($hour24, $hour12, $minute, $second); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 71 | my $ap; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # First, normalize am/pm indicator | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 71 | ▶ | if (defined $ampm && length $ampm) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ampm and length $ampm
MC/DC50%1/2
defined $ampm and length $ampm
defined $ampm
length $ampm
Truth table66%2/3
A and B
A= defined $ampmB= length $ampm
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 43 | $ap = $ap_from_ampm{lc $ampm}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 43 | ▶ | _bad ('am/pm indicator', $ampm) if !defined $ap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | # Check that the hour is in bounds | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 67 | ▶ | _bad('hour', $inh) if $inh !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 65 | ▶ | if (defined $ap) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # Range is from 1 to 12 | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 39 | ▶ | _bad('hour', $inh) if $inh < 1 || $inh > 12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inh < 1 or $inh > 12
MC/DC100%2/2
$inh < 1 or $inh > 12
$inh < 1
$inh > 12
Truth table100%3/3
A or B
A= $inh < 1B= $inh > 12
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | $hour12 = 0 + $inh; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 36 | ▶ | $hour24 = $hour12 == 12? 0 : $hour12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 36 | ▶ | $hour24 += 12 if $ap eq 'p'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | else | ||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # Range is from 0 to 23 | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 26 | ▶ | _bad('hour', $inh) if $inh < 0 || $inh > 23; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inh < 0 or $inh > 23
MC/DC50%1/2
$inh < 0 or $inh > 23
$inh < 0
$inh > 23
Truth table66%2/3
A or B
A= $inh < 0B= $inh > 23
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 24 | $hour24 = $inh; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 24 | ▶ | $hour12 = $hour24 > 12? $hour24 - 12 : $hour24 == 0? 12 : 0 + $hour24; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 24 | ▶ | $ap = $hour24 < 12? 'a' : 'p'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 60 | $hour24 = _lead0($hour24); | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | # Minute check: Numeric, range 0 to 59. | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 60 | ▶ | _bad('minute', $inm) if $inm !~ /\A\s* \d+ \s*\z/x || $inm < 0 || $inm > 59; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $inm =~ /\A\s* \d+ \s*\z/x or $inm < 0 or $inm > 59
not $inm =~ /\A\s* \d+ \s*\z/x or $inm < 0
MC/DC66%2/3
not $inm =~ /\A\s* \d+ \s*\z/x or $inm < 0 or $inm > 59
not $inm =~ /\A\s* \d+ \s*\z/x
$inm < 0
$inm > 59
Truth table75%3/4
not(A) or B or C
A= not $inm =~ /\A\s* \d+ \s*\z/xB= $inm < 0C= $inm > 59
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 57 | $minute = _lead0($inm); | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | # Second check: Numeric, range 0 to 59. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 57 | ▶ | if (defined $ins && length $ins) # second is optional! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ins and length $ins
MC/DC100%2/2
defined $ins and length $ins
defined $ins
length $ins
Truth table100%3/3
A and B
A= defined $insB= length $ins
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 44 | ▶ | _bad('second', $ins) if $ins !~ /\A\s* \d+ \s*\z/x || $ins < 0 || $ins > 59; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $ins =~ /\A\s* \d+ \s*\z/x or $ins < 0 or $ins > 59
not $ins =~ /\A\s* \d+ \s*\z/x or $ins < 0
MC/DC66%2/3
not $ins =~ /\A\s* \d+ \s*\z/x or $ins < 0 or $ins > 59
not $ins =~ /\A\s* \d+ \s*\z/x
$ins < 0
$ins > 59
Truth table75%3/4
not(A) or B or C
A= not $ins =~ /\A\s* \d+ \s*\z/xB= $ins < 0C= $ins > 59
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 41 | $second = $ins; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | else | ||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 13 | $second = 0; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 54 | $second = _lead0($second); | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 54 | my $sec_since_midnight = $second + 60 * ($minute + 60 * $hour24); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 54 | ▶ | return wantarray? ($hour24, $minute, $second, $hour12, $ap, $sec_since_midnight) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | : { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | h12 => $hour12, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | h24 => $hour24, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | hour => $hour24, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | min => $minute, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | sec => $second, | ||||||||||||||||||||||||||||||||||||||||||
| 272 | ampm => $ap, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | since_midnight => $sec_since_midnight, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | sub normalize_ymd | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 118 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ymd: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 118 | ▶ | _croak "Too few arguments to normalize_ymd" if @_ < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 117 | ▶ | _croak "Too many arguments to normalize_ymd" if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 116 | my ($iny, $inm, $ind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 116 | my ($year, $month, $day); | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 116 | _setup_locale(); | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | # First, check year. | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 116 | $year = normalize_year($iny); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | # Decode the month. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 113 | $month = normalize_month($inm); | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # Day: Numeric and within range for the given month/year | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 108 | ▶ | _bad('day', $ind) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $ind =~ /\A\s* \d+ \s*\z/x or $ind < 1 or $ind > days_in($month, $year)
not $ind =~ /\A\s* \d+ \s*\z/x or $ind < 1
MC/DC33%1/3
not $ind =~ /\A\s* \d+ \s*\z/x or $ind < 1 or $ind > days_in($month, $year)
not $ind =~ /\A\s* \d+ \s*\z/x
$ind < 1
$ind > days_in($month, $year)
Truth table50%2/4
not(A) or B or C
A= not $ind =~ /\A\s* \d+ \s*\z/xB= $ind < 1C= $ind > days_in($month, $year)
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | if $ind !~ /\A\s* \d+ \s*\z/x || $ind < 1 || $ind > days_in($month, $year); | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 95 | $day = _lead0($ind); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 95 | my $dow = _dow($year, $month, $day); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 95 | ▶ | return ($year, $month, $day, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | $dow, $Day_Name[$dow], $Day_Abbr[$dow], | ||||||||||||||||||||||||||||||||||||||||||
| 301 | $Mon_Name[$month], $Mon_Abbr[$month]) | ||||||||||||||||||||||||||||||||||||||||||
| 302 | if wantarray; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | return | ||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 22 | year => $year, mon => $month, day => $day, | |||||||||||||||||||||||||||||||||||||||||
| 307 | dow => $dow, | ||||||||||||||||||||||||||||||||||||||||||
| 308 | dow_name => $Day_Name[$dow], | ||||||||||||||||||||||||||||||||||||||||||
| 309 | dow_abbr => $Day_Abbr[$dow], | ||||||||||||||||||||||||||||||||||||||||||
| 310 | mon_name => $Mon_Name[$month], | ||||||||||||||||||||||||||||||||||||||||||
| 311 | mon_abbr => $Mon_Abbr[$month], | ||||||||||||||||||||||||||||||||||||||||||
| 312 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | sub normalize_ymdhms | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ymdhms: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 14 | ▶ | _croak "Too few arguments to normalize_ymdhms" if @_ < 5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 13 | ▶ | _croak "Too many arguments to normalize_ymdhms" if @_ > 7; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 12 | my ($iny, $inmon, $ind, $inhr, $inmin, $insec, $inampm) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 12 | my $date = normalize_ymd($iny, $inmon, $ind); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 12 | my $time = normalize_hms($inhr, $inmin, $insec, $inampm); | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | return ($date->{year}, $date->{mon}, $date->{day}, | ||||||||||||||||||||||||||||||||||||||||||
| 325 | $time->{hour}, $time->{min}, $time->{sec}) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 12 | ▶ | if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 6 | return { %$date, %$time }; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | # Normalize values returned from Regexp::Common::time | ||||||||||||||||||||||||||||||||||||||||||
| 332 | sub normalize_rct | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_rct: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 15 | my ($type, @values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 15 | $type =~ tr/24//d; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 15 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # First element is "whole match", which is useless here. | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 15 | shift @values; | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 15 | my ($yr, $mo, $dy, $hr, $mn, $sc, $tz, $am); | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # How we proceed depends on which pattern captured the values. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 15 | ▶ | if ($type eq 'iso') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ($yr, $mo, $dy, $hr, $mn, $sc) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | return normalize_ymdhms($yr, $mo, $dy, $hr, $mn, $sc); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | elsif ($type eq 'mail') | ||||||||||||||||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | ($dy, $mo, $yr, $hr, $mn, $sc) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | local $use_mail_months = 1; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | return normalize_ymdhms($yr, $mo, $dy, $hr, $mn, $sc); | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | elsif ($type eq 'american') | ||||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | ($mo, $dy, $yr) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | $yr =~ s/\A'//; # "american" year might have leading apostrophe | |||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | return normalize_ymd($yr, $mo, $dy); | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | elsif ($type eq 'ymd') | ||||||||||||||||||||||||||||||||||||||||||
| 362 | { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 2 | ($yr, $mo, $dy) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 2 | return normalize_ymd($yr, $mo, $dy); | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | elsif ($type eq 'mdy') | ||||||||||||||||||||||||||||||||||||||||||
| 367 | { | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | ($mo, $dy, $yr) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | return normalize_ymd($yr, $mo, $dy); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | elsif ($type eq 'dmy') | ||||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | ($dy, $mo, $yr) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | return normalize_ymd($yr, $mo, $dy); | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif ($type eq 'hms') | ||||||||||||||||||||||||||||||||||||||||||
| 377 | { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | ($hr, $mn, $sc, $am) = @values; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 2 | return normalize_hms($hr, $mn, $sc, $am); | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | else | ||||||||||||||||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | _croak qq{Unknown Regexp::Common::time pattern: "$type"}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | # Like normalize_ymd, but only returns the Y, M, and D values. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # So you can do: $date = join '/' => normalize_ymd3 ($input_yr, $input_mo, $input_dy); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | sub normalize_ymd3 | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ymd3: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | ▶ | _croak "Too few arguments to normalize_ymd3" if @_ < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | _croak "Too many arguments to normalize_ymd3" if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | my @ymd = normalize_ymd(@_); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | return @ymd[0,1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | # Like normalize_ym, but only returns the Y, M, and D values. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # So you can do: $date = join '/' => normalize_ym3 ($input_yr, $input_mo); | ||||||||||||||||||||||||||||||||||||||||||
| 399 | sub normalize_ym3 | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ym3: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | _croak "Too few arguments to normalize_ym3" if @_ < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | _croak "Too many arguments to normalize_ym3" if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my @ymd = normalize_ym(@_); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return @ymd[0,1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | # Like normalize_hms, but only returns the H, M, and S values. | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # So you can do: $time = join ':' => normalize_hms3 ($input_hr, $input_min, $input_sec); | ||||||||||||||||||||||||||||||||||||||||||
| 409 | sub normalize_hms3 | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_hms3: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | _croak "Too few arguments to normalize_hms3" if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | _croak "Too many arguments to normalize_hms3" if @_ > 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my @hms = normalize_hms(@_); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | return @hms[0,1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | sub normalize_month | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 238 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_month: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 238 | ▶ | _croak "Too few arguments to normalize_month" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 237 | ▶ | _croak "Too many arguments to normalize_month" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 236 | _setup_locale; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 236 | my $inm = shift; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 236 | my $month; | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 236 | ▶ | _bad('month', $inm) if !defined $inm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | # Decode the month. | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 235 | ▶ | if ($inm =~ /\A\s* \d+ \s*\z/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # Numeric. Simple 1-12 check. | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 136 | ▶ | _bad('month', $inm) if $inm < 1 || $inm > 12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inm < 1 or $inm > 12
MC/DC100%2/2
$inm < 1 or $inm > 12
$inm < 1
$inm > 12
Truth table100%3/3
A or B
A= $inm < 1B= $inm > 12
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 130 | $month = $inm; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | else | ||||||||||||||||||||||||||||||||||||||||||
| 435 | { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | # Might be a character month name | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 99 | ▶ | if ($use_mail_months) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | ▶ | _init_mail_months if !defined $mail_month_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | $month = $mail_month_number->{uc $inm}; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | else | ||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 97 | $month = $number_of{uc $inm}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 99 | ▶ | _bad('month', $inm) if !defined $month; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 220 | return _lead0($month); | |||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | sub normalize_year | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 161 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_year: called CC=8 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 161 | ▶ | _croak "Too few arguments to normalize_year" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 161 | ▶ | _croak "Too many arguments to normalize_year" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 161 | my $iny = shift; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 161 | ▶ | if ($iny =~ /\A\s* \d{4} \s*\z/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | { | ||||||||||||||||||||||||||||||||||||||||||
| 459 | # Four-digit year. Good. | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 124 | return sprintf '%04d', $iny+0; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 37 | ▶ | if ($iny =~ /\A\s* \d{2} \s*\z/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | { | ||||||||||||||||||||||||||||||||||||||||||
| 465 | # Two-digit year. Guess the century. | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | # If curr yy is <= 50, current century numbers are 0 - yy+50 | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 28 | ▶ | if ($current_yy <= 50) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 28 | ▶ | return $iny + 100 * ($iny <= $current_yy+50? $current_century : $current_century-1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | # If curr yy is > 50, current century numbers are yy-50 - 99 | ||||||||||||||||||||||||||||||||||||||||||
| 473 | else | ||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | return $iny + 100 * ($iny <= $current_yy-50? $current_century+1 : $current_century); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 9 | _bad('year', $iny); | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | sub normalize_ym | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 38 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_ym: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 38 | ▶ | _croak "Too few arguments to normalize_ym" if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 37 | ▶ | _croak "Too many arguments to normalize_ym" if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 36 | my ($iny, $inm) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 36 | my ($year, $month) = (normalize_year($iny), normalize_month($inm)); | |||||||||||||||||||||||||||||||||||||||||
| 489 | 28 | my $day = days_in ($month, $year); | |||||||||||||||||||||||||||||||||||||||||
| 490 | 28 | return normalize_ymd($year, $month, $day); | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | sub normalize_time | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_time: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | _croak "Too many arguments to normalize_time" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | _bad ('time', $_[0]) if @_ == 1 && $_[0] !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and not $_[0] =~ /\A\s* \d+ \s*\z/x
MC/DC0%0/2
@_ == 1 and not $_[0] =~ /\A\s* \d+ \s*\z/x
@_ == 1
not $_[0] =~ /\A\s* \d+ \s*\z/x
Truth table0%0/3
A and not(B)
A= @_ == 1B= not $_[0] =~ /\A\s* \d+ \s*\z/x
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | my @t = @_? localtime($_[0]) : localtime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return _normalize_gm_and_local_times(@t); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | sub normalize_gmtime | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_gmtime: called CC=5 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 2 | ▶ | _croak "Too many arguments to normalize_gmtime" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | ▶ | _bad ('time', $_[0]) if @_ == 1 && $_[0] !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and not $_[0] =~ /\A\s* \d+ \s*\z/x
MC/DC0%0/2
@_ == 1 and not $_[0] =~ /\A\s* \d+ \s*\z/x
@_ == 1
not $_[0] =~ /\A\s* \d+ \s*\z/x
Truth table33%1/3
A and not(B)
A= @_ == 1B= not $_[0] =~ /\A\s* \d+ \s*\z/x
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | ▶ | my @t = @_? gmtime($_[0]) : gmtime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | return _normalize_gm_and_local_times(@t); | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | sub _normalize_gm_and_local_times | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_gm_and_local_times: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | my @t = @_; | |||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | _setup_locale(); | |||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | ▶ | if (wantarray) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | { | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | my ($h24, $min, $sec, $h12, $ap, $ssm) = normalize_hms ($t[2], $t[1], $t[0]); | |||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | my ($y4, $mon, $day, $dow, $dow_name, $dow_abbr, $mon_name, $mon_abbr) | |||||||||||||||||||||||||||||||||||||||||
| 520 | = normalize_ymd ($t[5] + 1900, $t[4] + 1, $t[3]); | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | return ($sec, $min, $h24, | |||||||||||||||||||||||||||||||||||||||||
| 523 | $day, $mon, $y4, | ||||||||||||||||||||||||||||||||||||||||||
| 524 | $dow, $t[7], $t[8], | ||||||||||||||||||||||||||||||||||||||||||
| 525 | $h12, $ap, $ssm, | ||||||||||||||||||||||||||||||||||||||||||
| 526 | $dow_name, $dow_abbr, | ||||||||||||||||||||||||||||||||||||||||||
| 527 | $mon_name, $mon_abbr); | ||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | # Scalar. Return hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | my $hms_href = normalize_hms ($t[2], $t[1], $t[0]); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | my $ymd_href = normalize_ymd ($t[5] + 1900, $t[4] + 1, $t[3]); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | return { %$hms_href, %$ymd_href, yday => $t[7], isdst => $t[8] }; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | sub mon_name | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mon_name: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 17 | ▶ | _croak "Too many arguments to mon_name" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 16 | ▶ | _croak "Too few arguments to mon_name" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 15 | my $mon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 15 | ▶ | _croak qq{Non-integer month "$mon" for mon_name} if $mon !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 14 | ▶ | _bad('month', $mon) if $mon < 1 || $mon > 12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mon < 1 or $mon > 12
MC/DC100%2/2
$mon < 1 or $mon > 12
$mon < 1
$mon > 12
Truth table100%3/3
A or B
A= $mon < 1B= $mon > 12
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 12 | _setup_locale; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 12 | return $Mon_Name[$mon]; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | sub mon_abbr | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mon_abbr: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 17 | ▶ | _croak "Too many arguments to mon_abbr" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 16 | ▶ | _croak "Too few arguments to mon_abbr" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 15 | my $mon = shift; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 15 | ▶ | _croak qq{Non-integer month "$mon" for mon_abbr} if $mon !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 14 | ▶ | _bad('month', $mon) if $mon < 1 || $mon > 12; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mon < 1 or $mon > 12
MC/DC100%2/2
$mon < 1 or $mon > 12
$mon < 1
$mon > 12
Truth table100%3/3
A or B
A= $mon < 1B= $mon > 12
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 12 | _setup_locale; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 12 | return $Mon_Abbr[$mon]; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | sub day_name | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
day_name: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 11 | ▶ | _croak "Too many arguments to day_name" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 10 | ▶ | _croak "Too few arguments to day_name" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 9 | my $day = shift; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 9 | ▶ | _croak qq{Non-integer weekday "$day" for day_name} if $day !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 8 | ▶ | _bad('weekday-number', $day) if $day < 0 || $day > 6; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$day < 0 or $day > 6
MC/DC50%1/2
$day < 0 or $day > 6
$day < 0
$day > 6
Truth table66%2/3
A or B
A= $day < 0B= $day > 6
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 7 | _setup_locale; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 7 | return $Day_Name[$day]; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | sub day_abbr | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
day_abbr: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 11 | ▶ | _croak "Too many arguments to day_abbr" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 10 | ▶ | _croak "Too few arguments to day_abbr" if @_ < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 9 | my $day = shift; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 9 | ▶ | _croak qq{Non-integer weekday "$day" for day_abbr} if $day !~ /\A\s* \d+ \s*\z/x; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 8 | ▶ | _bad('weekday-number', $day) if $day < 0 || $day > 6; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$day < 0 or $day > 6
MC/DC50%1/2
$day < 0 or $day > 6
$day < 0
$day > 6
Truth table66%2/3
A or B
A= $day < 0B= $day > 6
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 7 | _setup_locale; | |||||||||||||||||||||||||||||||||||||||||
| 581 | 7 | return $Day_Abbr[$day]; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 585 | __END__ | ||||||||||||||||||||||||||||||||||||||||||