| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Date::HolidayParser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # A parser of ~/.holiday-style files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # The format is based off of the holiday files found bundled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # with the plan program, not any official spec. This because no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # official spec could be found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright (C) Eskild Hustvedt 2006, 2007, 2008, 2010 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # under the same terms as Perl itself. There is NO warranty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Date::HolidayParser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use constant { true => 1, false => 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Exportable functions are EasterCalc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my @EXPORT_OK = qw(EasterCalc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Deprecated silencing variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | our $BeSilent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Version number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | $VERSION = 0.4_3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # --- Attributes --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | has 'file' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | has 'silent' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | has '_cache' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | has '_parsed' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # TODO: Move to arrayref(?) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # --- Public methods --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Purpose: Get the holiday information for YEAR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Usage: my $HashRef = $object->get(YEAR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 56 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=6 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 56 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 56 | my $Year = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 56 | ▶ | if(not defined $Year) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | carp('Date::HolidayParser->get needs an parameter: The year to parse'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | elsif($Year =~ /\D/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | carp("Date::HolidayParser: The year must be a digit (was '$Year')"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | elsif($Year < 1971 || $Year > 2037) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Year < 1971 or $Year > 2037
MC/DC0%0/2
$Year < 1971 or $Year > 2037
$Year < 1971
$Year > 2037
Truth table33%1/3
A or B
A= $Year < 1971B= $Year > 2037
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | carp('Date::HolidayParser: Can\'t parse years lower than 1971 or higher than 2037'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 56 | ▶ | if(not $self->_cache->{$Year}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | $self->_cache->{$Year} = $self->_interperate_year($Year); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 56 | return($self->_cache->{$Year}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # --- Public functions --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Easter calculation using the gauss algorithm. See: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # http://en.wikipedia.org/wiki/Computus#Gauss.27s_algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Parts of the code stolen from Kenny Fowler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Purpose: Calculate on which day easter occurs on in the year YEAR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Usage: $EasterYDay = EasterCalc(YEAR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # YEAR must be absolute and not relative to 1900 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | ▶ | sub EasterCalc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EasterCalc: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | my $year = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 15 | my $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my $l; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 15 | my $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 15 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 15 | my $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 15 | my $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 15 | my $NewTime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 15 | $c = int($year/100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 15 | $l = $year % 19; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 15 | $k = int(($c - 17)/25); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 15 | $d = (15 + $c - int($c/4) - int(($c-$k)/3) + 19*$l) % 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 15 | $r = $d - int(($d + int($l/11))/29); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 15 | $j = ($year + int($year/4) + $r + 2 - $c + int($c/4)) % 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 15 | my $number = 28 + $r - $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 15 | ▶ | if ($number > 31) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 15 | $number = $number - 31; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | $year = $year - 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 15 | $NewTime = POSIX::mktime(0, 0, 0, $number, 3, $year); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $year = $year - 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $NewTime = POSIX::mktime(0, 0, 0, $number, 2, $year); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 15 | my ($easter_sec,$easter_min,$easter_hour,$easter_mday,$easter_mon,$easter_year,$easter_wday,$easter_yday,$easter_isdst) = localtime($NewTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 15 | return($easter_yday); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # --- Moose construction methods --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | sub BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | ▶ | if (defined $file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | unshift(@_,'file',$file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | return $class->SUPER::BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub BUILD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | if(not $self->file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | carp('Needs a parameter: Path to the holiday file to load and parse'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | elsif(not -e $self->file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | carp($self->file.': does not exist'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | $self->_load_and_parse($self->file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # --- Private methods --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # Purpose: Add a parsed event to the final hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # Usage: obj->_addParsedEvent(FinalParsing, final_mon, final_mday, holidayName, HolidayType, finalYDay, PosixYear); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # The reason this is used is because submodules, ie. ::iCalendar, overrides or wraps this to generate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # data specific to that module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | sub _addParsedEvent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 55 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_addParsedEvent: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 55 | my($self,$FinalParsing,$final_mon,$final_mday,$HolidayName,$holidayType,$finalYDay,$PosixYear) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 55 | $FinalParsing->{$final_mon}{$final_mday}{$HolidayName} = $holidayType; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Purpose: Calculate a NumericYDay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Usage: $CreativeParser{FinalYDay} = _HCalc_NumericYDay($CreativeParser{NumericYDay}, $CreativeParser{AddDays}, $CreativeParser{SubtDays}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | sub _HCalc_NumericYDay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 50 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_HCalc_NumericYDay: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 50 | my ($DAY, $ADD_DAYS, $SUBTRACT_DAYS) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 50 | ▶ | if(defined($ADD_DAYS)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 15 | $DAY += $ADD_DAYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 50 | ▶ | if(defined($SUBTRACT_DAYS)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | $DAY -= $SUBTRACT_DAYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # mday begins on 1 not 0 - we use mday for all calculations, thus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # make the day 1-365 instead of 0-364 here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 50 | $DAY++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 50 | return($DAY); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # Purpose: Return the English day name of the year day supplied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Usage: $DayName = _Holiday_DayName(INTEGER_NUMBER, YEAR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub _Holiday_DayName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 95 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Holiday_DayName: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 95 | my $yDay = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 95 | my $year = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 95 | $year -= 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 95 | my $PosixTime = POSIX::mktime(0, 0, 0, $yDay, 0, $year); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 95 | ▶ | die("*** _Holiday_DayName: For some reason mktime returned undef!. Was running: \"POSIX::mktime(0, 0, 0, $yDay, 0, $year)\".\nYou've probably got a loop that has started looping eternally. This error is fatal") unless(defined($PosixTime)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 95 | my %NumToDayHash = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 => 'sunday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 => 'monday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 => 'tuesday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 => 'wednesday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 => 'thursday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 => 'friday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 => 'saturday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 7 => 'sunday', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 95 | my ($DayName_sec,$DayName_min,$DayName_hour,$DayName_mday,$DayName_mon,$DayName_year,$DayName_wday,$DayName_yday,$DayName_isdst) = localtime($PosixTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 95 | return($NumToDayHash{$DayName_wday}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Purpose: Return the yday of the supplied unix time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Usage: $YDay = _Get_YDay(UNIX_TIME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | sub _Get_YDay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 35 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_Get_YDay: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 35 | my $Unix_Time = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 35 | ▶ | warn("_Get_YDay: Invalid usage: must be numeric. Got \"$Unix_Time\"") and return(undef) if $Unix_Time =~ /\D/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$Unix_Time =~ /\D/ && (warn(qq[_Get_YDay: Invalid usage: must be numeric. Got "$Unix_Time"]) && (return undef))
warn qq[_Get_YDay: Invalid usage: must be numeric. Got "$Unix_Time"] and return undef
MC/DC0%0/2
$Unix_Time =~ /\D/ && (warn(qq[_Get_YDay: Invalid usage: must be numeric. Got "$Unix_Time"]) && (return undef))
$Unix_Time =~ /\D/
warn qq[_Get_YDay: Invalid usage: must be numeric. Got "$Unix_Time"]
Truth table33%1/3
A && B
A= $Unix_Time =~ /\D/B= warn qq[_Get_YDay: Invalid usage: must be numeric. Got "$Unix_Time"]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 35 | my ($get_sec,$get_min,$get_hour,$get_mday,$get_mon,$get_year,$get_wday,$get_yday,$get_isdst) = localtime($Unix_Time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 35 | return($get_yday); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Purpose: Print a warning about some error during the holiday parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Usage: $self->_HolidayError(LINE_NO, FILENAME, ERROR, ACTION_TAKEN); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub _HolidayError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_HolidayError: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->_PrintError('Error',@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Purpose: Print a syntax error in a holiday file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # Usage: $self->_SyntaxError(LINE_NO, FILENAME, ERROR, ACTION_TAKEN); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | sub _SyntaxError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_SyntaxError: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $self->_PrintError('Syntax error',@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Purpose. Actually print the error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # Usage: $self->_PrintError(TYPE,LINE,FILE,ERROR,ACTION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | sub _PrintError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_PrintError: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($BeSilent and not $self->silent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$Date::HolidayParser::BeSilent and not $self->silent
MC/DC0%0/2
$Date::HolidayParser::BeSilent and not $self->silent
$Date::HolidayParser::BeSilent
not $self->silent
Truth table0%0/3
A and not(B)
A= $Date::HolidayParser::BeSilentB= not $self->silent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $self->silent(true); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | warn('$Date::HolidayParser::BeSilent is deprecated. Use the silent attribute instead\n'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | elsif(not $self->silent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my($type,$line,$file,$error,$action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | warn("*** Holiday parser: $type: $error on line $line in $file. $action"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # Purpose: Interperate and calculate the holiday file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Usage: $self->_interperate_year(YEAR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub _interperate_year | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_interperate_year: called CC=47 SCAR=49.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | my $Year = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | my $PosixYear = $Year - 1900; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | my $FinalParsing = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | foreach my $LineNo (keys(%{$self->_parsed})) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 50 | my ($FinalYDay, $NumericYDay); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 50 | my $CreativeParser = $self->_parsed->{$LineNo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 50 | my $HolidayName = $self->_parsed->{$LineNo}{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 50 | my $File = $self->file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 50 | my %MonthMapping = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 'january' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 'february' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 'march' => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 'april' => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 'may' => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 'june' => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 'july' => 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 'august' => 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 'september' => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 'october' => 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 'november' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 'december' => 11, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ); # Hash mapping the month name to a numeric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 50 | ▶ | if(defined($CreativeParser->{AddEaster})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 15 | $NumericYDay = EasterCalc($Year); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 50 | ▶ | if(defined($CreativeParser->{MonthDay})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 10 | my $month = $CreativeParser->{MonthDay}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 10 | my $day = $CreativeParser->{MonthDay}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 10 | $month =~ s/^(\d+)-(\d+)$/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 10 | $day =~ s/^(\d+)-(\d+)$/$2/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 10 | my $PosixTime = POSIX::mktime(0, 0, 0, $day, $month, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | $NumericYDay = _Get_YDay($PosixTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 50 | ▶ | unless(defined($CreativeParser->{IsMonth}) or defined($NumericYDay)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $CreativeParser->{"IsMonth"} or defined $NumericYDay
MC/DC0%0/2
defined $CreativeParser->{"IsMonth"} or defined $NumericYDay
defined $CreativeParser->{"IsMonth"}
defined $NumericYDay
Truth table66%2/3
A or B
A= defined $CreativeParser->{"IsMonth"}B= defined $NumericYDay
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $self->_SyntaxError($LineNo, $File, 'I had no day-of-the-year nor a month defined after parsing', 'Ignoring this line'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 50 | ▶ | if(defined($CreativeParser->{MustBeDay})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # If IsMonth is defined then find a NumericYDay that we can use so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # the NumericYDay parsing below can do all of the heavy lifting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 20 | ▶ | if (defined($CreativeParser->{IsMonth}) and defined($CreativeParser->{Number})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $CreativeParser->{"IsMonth"} and defined $CreativeParser->{"Number"}
MC/DC50%1/2
defined $CreativeParser->{"IsMonth"} and defined $CreativeParser->{"Number"}
defined $CreativeParser->{"IsMonth"}
defined $CreativeParser->{"Number"}
Truth table66%2/3
A and B
A= defined $CreativeParser->{"IsMonth"}B= defined $CreativeParser->{"Number"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 15 | my $PosixTime = POSIX::mktime(0, 0, 0, 1, $MonthMapping{$CreativeParser->{IsMonth}}, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 15 | my $proper_yday = _Get_YDay($PosixTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 15 | ▶ | unless(defined($CreativeParser->{Number})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $self->_HolidayError($LineNo, $File, '$CreativeParser->{Number} is undef', 'Skipping this line. This is probably a bug in the parser'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 15 | ▶ | if($CreativeParser->{Number} eq 'last') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Find the first of the set day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 15 | ▶ | if(_Holiday_DayName($proper_yday, $Year) eq $CreativeParser->{MustBeDay}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 10 | $proper_yday++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Find the last of the set day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | my $Last_YDay = $proper_yday; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 25 | ▶ | if(_Holiday_DayName($proper_yday, $Year) eq $CreativeParser->{MustBeDay}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 25 | $proper_yday += 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 25 | my $MKTime = POSIX::mktime(0, 0, 0, $proper_yday, 0, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 25 | my ($detect_sec,$detect_min,$detect_hour,$detect_mday,$detect_mon,$detect_year,$detect_wday,$detect_yday,$detect_isdst) = localtime($MKTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # If $detect_mon is not equal to $MonthMapping{$CreativeParser->{IsMonth}} then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # we're now on the next month and have found the last of the day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 25 | ▶ | unless($detect_mon eq $MonthMapping{$CreativeParser->{IsMonth}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 20 | $Last_YDay = $proper_yday; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | $NumericYDay = $Last_YDay; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 5 | $CreativeParser->{BeforeOrAfter} = 'before'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # Parse the final | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | $NumericYDay = $proper_yday; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | ▶ | if($CreativeParser->{Number} eq 'first') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | $CreativeParser->{BeforeOrAfter} = 'after'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | elsif($CreativeParser->{Number} eq 'second') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 5 | $CreativeParser->{BeforeOrAfter} = 'after'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | $CreativeParser->{AddDays} = 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | elsif($CreativeParser->{Number} eq 'third') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $CreativeParser->{BeforeOrAfter} = 'after'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $CreativeParser->{AddDays} = 14; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | elsif($CreativeParser->{Number} eq 'fourth') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $CreativeParser->{BeforeOrAfter} = 'after'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $CreativeParser->{AddDays} = 21; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $self->_HolidayError($LineNo, $File, "\$CreativeParer->{Number} is \"$CreativeParser->{Number}\"", 'This is a bug in the parser. This line will be ignored') and next unless $CreativeParser->{Number} eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$CreativeParser->{'Number'} eq 'null' || $self->_HolidayError($LineNo, $File, qq[\$CreativeParer->{Number} is "$CreativeParser->{'Number'}"], 'This is a bug in the parser. This line will be ignored') && (next)
$self->_HolidayError($LineNo, $File, qq[\$CreativeParer->{Number} is "$CreativeParser->{"Number"}"], "This is a bug in the parser. This line will be ignored") and next
MC/DC0%0/2
$CreativeParser->{'Number'} eq 'null' || $self->_HolidayError($LineNo, $File, qq[\$CreativeParer->{Number} is "$CreativeParser->{'Number'}"], 'This is a bug in the parser. This line will be ignored') && (next)
$CreativeParser->{'Number'} eq 'null'
$self->_HolidayError($LineNo, $File, qq[\$CreativeParer->{Number} is "$CreativeParser->{"Number"}"], "This is a bug in the parser. This line will be ignored")
Truth table0%0/3
A || B
A= $CreativeParser->{'Number'} eq 'null'B= $self->_HolidayError($LineNo, $File, qq[\$CreativeParer->{Number} is "$CreativeParser->{"Number"}"], "This is a bug in the parser. This line will be ignored")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ▶ | elsif (defined($CreativeParser->{IsMonth}) and defined($CreativeParser->{DateNumeric})) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $CreativeParser->{"IsMonth"} and defined $CreativeParser->{"DateNumeric"}
MC/DC0%0/2
defined $CreativeParser->{"IsMonth"} and defined $CreativeParser->{"DateNumeric"}
defined $CreativeParser->{"IsMonth"}
defined $CreativeParser->{"DateNumeric"}
Truth table33%1/3
A and B
A= defined $CreativeParser->{"IsMonth"}B= defined $CreativeParser->{"DateNumeric"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 5 | my $PosixTime = POSIX::mktime(0, 0, 0, $CreativeParser->{DateNumeric}, $MonthMapping{$CreativeParser->{IsMonth}}, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 5 | $NumericYDay = _Get_YDay($PosixTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | elsif (defined($CreativeParser->{IsMonth})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->_SyntaxError($LineNo, $File, 'There is a month defined but no way to find out which day of the month it is referring to', 'Ignoring this line.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 20 | ▶ | if(defined($NumericYDay)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # Parse the main NumericYDay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 20 | $FinalYDay = _HCalc_NumericYDay($NumericYDay, $CreativeParser->{AddDays}, $CreativeParser->{SubtDays}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 20 | ▶ | unless(defined($CreativeParser->{BeforeOrAfter})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->_SyntaxError($LineNo, $File, 'It was not defined if the day should be before or after', 'Defaulting to before. This is likely to cause calculation mistakes.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $CreativeParser->{BeforeOrAfter} = 'before'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 20 | ▶ | if($CreativeParser->{BeforeOrAfter} eq 'before') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # Before parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Okay, we need to find the closest $CreativeParser{MustBeDay} before $CreativeParser{FinalYDay} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | while (1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 15 | ▶ | if(_Holiday_DayName($FinalYDay, $Year) eq $CreativeParser->{MustBeDay}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 10 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 5 | $FinalYDay = $FinalYDay - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | elsif ($CreativeParser->{BeforeOrAfter} eq 'after') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # After parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # Okay, we need to find the closest $CreativeParser{MustBeDay} after $CreativeParser{FinalYDay} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 10 | while (1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 40 | ▶ | if(_Holiday_DayName($FinalYDay, $Year) eq $CreativeParser->{MustBeDay}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 10 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 30 | $FinalYDay = $FinalYDay + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $self->_HolidayError($LineNo, $File, "BeforeOrAfter was set to an invalid value ($CreativeParser->{BeforeOrAfter})", 'This is a bug in the parser. This line will be ignored.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->_SyntaxError($LineNo, $File, 'A day is defined but no other way to find out when the day is could be found', 'Ignoring this line'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Calculate the yday of that day-of-the-month | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | elsif(defined($CreativeParser->{IsMonth})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | ▶ | unless(defined($CreativeParser->{DateNumeric})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->_SyntaxError($LineNo, $File, 'It was set which month the day should be on but no information about the day itself ', 'Ignoring this line'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | my $PosixTime = POSIX::mktime(0, 0, 0, $CreativeParser->{DateNumeric}, $MonthMapping{$CreativeParser->{IsMonth}}, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | my $proper_yday = _Get_YDay($PosixTime); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | $FinalYDay = _HCalc_NumericYDay($proper_yday, $CreativeParser->{AddDays}, $CreativeParser->{SubtDays}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # NumericYDay-only parsing is the simplest solution. This is pure and simple maths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | elsif(defined($NumericYDay)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # NumericYDay-only parsing is the simplest solution. This is pure and simple maths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 25 | ▶ | if(defined($CreativeParser->{MustBeDay})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->_SyntaxError($LineNo, $File, "It was set exactly which day the holiday should occur on and also that it should occur on $CreativeParser->{MustBeDay}", 'Ignoring the day requirement'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 25 | $FinalYDay = _HCalc_NumericYDay($NumericYDay, $CreativeParser->{AddDays}, $CreativeParser->{SubtDays}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Verify the use of the "every" keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 50 | ▶ | if(defined($CreativeParser->{Every}) and not defined($CreativeParser->{Number})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $CreativeParser->{"Every"} and not defined $CreativeParser->{"Number"}
MC/DC0%0/2
defined $CreativeParser->{"Every"} and not defined $CreativeParser->{"Number"}
defined $CreativeParser->{"Every"}
not defined $CreativeParser->{"Number"}
Truth table66%2/3
A and not(B)
A= defined $CreativeParser->{"Every"}B= not defined $CreativeParser->{"Number"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $self->_SyntaxError($LineNo, $File, 'Use of the "every" keyword without any trailing month', 'Ignoring the "every" keyword.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 50 | ▶ | if(defined($CreativeParser->{Every}) and defined($CreativeParser->{Length})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $CreativeParser->{"Every"} and defined $CreativeParser->{"Length"}
MC/DC0%0/2
defined $CreativeParser->{"Every"} and defined $CreativeParser->{"Length"}
defined $CreativeParser->{"Every"}
defined $CreativeParser->{"Length"}
Truth table66%2/3
A and B
A= defined $CreativeParser->{"Every"}B= defined $CreativeParser->{"Length"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $self->_SyntaxError($LineNo, $File, 'Use of both "every" and "length"', 'This might give unpredictable results.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # Do the final parsing and add it to the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 50 | ▶ | if(defined($FinalYDay) and $FinalYDay =~ /^\d+$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $FinalYDay and $FinalYDay =~ /^\d+$/
MC/DC0%0/2
defined $FinalYDay and $FinalYDay =~ /^\d+$/
defined $FinalYDay
$FinalYDay =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $FinalYDayB= $FinalYDay =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 50 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 55 | ▶ | if(defined($FinalYDay)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 55 | my ($final_sec,$final_min,$final_hour,$final_mday,$final_mon,$final_year,$final_wday,$final_yday,$final_isdst) = localtime(POSIX::mktime(0, 0, 0, $FinalYDay, 0, $PosixYear)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 55 | $final_mon++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 55 | $self->_addParsedEvent($FinalParsing, $final_mon, $final_mday, $HolidayName, $CreativeParser->{HolidayType}, $FinalYDay, $PosixYear); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 55 | ▶ | if(defined($CreativeParser->{Every}) and defined($CreativeParser->{Number})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $CreativeParser->{"Every"} and defined $CreativeParser->{"Number"}
MC/DC50%1/2
defined $CreativeParser->{"Every"} and defined $CreativeParser->{"Number"}
defined $CreativeParser->{"Every"}
defined $CreativeParser->{"Number"}
Truth table66%2/3
A and B
A= defined $CreativeParser->{"Every"}B= defined $CreativeParser->{"Number"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 5 | delete($CreativeParser->{Every}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 5 | ▶ | if($CreativeParser->{Number} ne 'second') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $self->_SyntaxError($LineNo, $File, "Nonsense use of $CreativeParser->{Number} along with \"every\"",'Ignoring the "every" keyword.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # Add 14 days | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | $FinalYDay += 14; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | ▶ | elsif(defined($CreativeParser->{Length}) and $CreativeParser->{Length} > 0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $CreativeParser->{"Length"} and $CreativeParser->{"Length"} > 0
MC/DC0%0/2
defined $CreativeParser->{"Length"} and $CreativeParser->{"Length"} > 0
defined $CreativeParser->{"Length"}
$CreativeParser->{"Length"} > 0
Truth table33%1/3
A and B
A= defined $CreativeParser->{"Length"}B= $CreativeParser->{"Length"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | $CreativeParser->{Length}-- or die('FATAL: attempted to reduce (--) length but it failed! This is a bug.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $FinalYDay++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 50 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | elsif(defined($FinalYDay)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | $self->_HolidayError($LineNo, $File, "Invalid FinalYDay ($FinalYDay) after finished parsing", 'This is a bug in the parser!'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->_HolidayError($LineNo, $File, 'No FinalYDay after finished parsing', 'This is a bug in the parser!'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 5 | return($FinalParsing); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # Purpose: Load and parse the holiday file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # Usage: $self->_load_and_parse(FILE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | sub _load_and_parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_and_parse: called CC=49 SCAR=48.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 6 | my $File = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 6 | ▶ | carp("$File does not exist") and return(undef) unless -e $File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-e $File || carp("$File does not exist") && (return undef)
carp("$File does not exist") and return undef
MC/DC0%0/2
-e $File || carp("$File does not exist") && (return undef)
-e $File
carp("$File does not exist")
Truth table33%1/3
A || B
A= -e $FileB= carp("$File does not exist")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 6 | ▶ | carp("$File is not readable") and return(undef) unless -r $File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-r $File || carp("$File is not readable") && (return undef)
carp("$File is not readable") and return undef
MC/DC0%0/2
-r $File || carp("$File is not readable") && (return undef)
-r $File
carp("$File is not readable")
Truth table33%1/3
A || B
A= -r $FileB= carp("$File is not readable")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 6 | ▶ | open(my $HolidayFile, '<' ,$File) or croak("Unable to open $File for reading"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 6 | my $LineNo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 6 | ▶ | while(my $Line = <$HolidayFile>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 132 | $LineNo++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 132 | ▶ | next if $Line =~ /^\s*[:;#]/;# Ignore these lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 60 | ▶ | next if $Line =~ /^\s*$/;# Ignore lines with only whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 60 | my $OrigLine = $Line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 60 | my $HolidayType; # red or none (see above) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | my $LineMode; # Is either PreDec or PostDec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # PreDec means that the holiday "mode" is declared before the name of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # the holiday. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # PostDec means that the holiday "mode" is declared after the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # of the holiday. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # Note that PreDec incorporated the functions of PostDec aswell, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # not the other way around | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 60 | ▶ | if($Line =~ /^\s*\"/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 42 | $LineMode = 'PostDec'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 18 | $LineMode = 'PreDec'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # Parse PreDec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 60 | ▶ | if($LineMode eq 'PreDec') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 18 | ▶ | while(not $Line =~ /^\"/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 18 | my $PreDec = $Line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 18 | $PreDec =~ s/^\s*(\w+)\s+.*$/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 18 | chomp($PreDec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 18 | $Line =~ s/^\s*$PreDec\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 18 | ▶ | unless(length($PreDec)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $self->_HolidayError($LineNo, $File, "LineMode=PreDec, but the predec parser recieved \"$PreDec\" as PreDec", 'Ignoring this predec'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 18 | ▶ | if($PreDec =~ /^(weekend|red)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 18 | $HolidayType = 'red'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | elsif ($PreDec =~ /^(black|small|blue|green|cyan|magenta|yellow)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # These are often just "formatting" declerations, and thus ignored by the day planner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # parser. In these cases PostDec usually declares more valid stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $HolidayType = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $Line =~ s/^[^"]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $HolidayType = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $self->_SyntaxError($LineNo, $File, "Unrecognized holiday type: \"$PreDec\".", 'Defaulting to "none"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $Line =~ s/^[^"]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # Get the holiday name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 60 | my $HolidayName = $Line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 60 | chomp($HolidayName); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 60 | $HolidayName =~ s/^\s*\"(.*)\".*$/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 60 | $Line =~ s/^\s*\".*\"//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 60 | ▶ | if ($HolidayName =~ /^\"*$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $self->_SyntaxError($LineNo, $File, 'The name of the holiday was not defined', 'Ignoring this line.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 60 | ▶ | if ($Line =~ /^\s*(weekend|red|black|small|blue|green|cyan|magenta|yellow)/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 6 | my $HolidayDec = $Line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 6 | $HolidayDec =~ s/^\s*(\w+)\s+.*$/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 6 | chomp($HolidayDec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 6 | $Line =~ s/^\s*$HolidayDec\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 6 | ▶ | if($HolidayDec =~ /^(weekend|red)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 6 | $HolidayType = 'red'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | elsif ($HolidayDec =~ /^(black|small|blue|green|cyan|magenta|yellow)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # These are just "formatting" keywords, so we ignore them here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | unless(defined($HolidayType) and $HolidayType eq 'red') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $HolidayType and $HolidayType eq "red"
MC/DC0%0/2
defined $HolidayType and $HolidayType eq "red"
defined $HolidayType
$HolidayType eq "red"
Truth table0%0/3
A and B
A= defined $HolidayTypeB= $HolidayType eq "red"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | $HolidayType = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $HolidayType = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | $self->_SyntaxError($LineNo, $File, "Unrecognized holiday type: \"$HolidayDec\".", 'Defaulting to "none"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 60 | ▶ | unless($Line =~ /^\s*on/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $self->_SyntaxError($LineNo, $File, 'Missing "on" keyword', 'Pretending it\'s there. This might give weird effects'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 60 | $Line =~ s/^\s*on\*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | # ================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # Parse main keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # ================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # This is the hardest part of the parser, now we get creative. We read each word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | # and run it through the parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 60 | my %CreativeParser; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 60 | foreach (split(/\s+/, $Line)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 312 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 258 | ▶ | if(/^(last|first|second|third|fourth)$/) # This is a number defining when a day should occur, usually used along with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # MustBeDay (below) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 18 | $CreativeParser{Number} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 18 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | elsif (/^(monday|tuesday|wednesday|thursday|friday|saturday|sunday)$/) # This defines which day the holiday should occur on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 24 | $CreativeParser{MustBeDay} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | elsif (m#^\d+[/\.]\d+\.?$#) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | { # This regexp gets numbers in the format XX/YY X/Y, XX.YY and X.Y | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # With an optional trailing . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 12 | s/\.$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 12 | my $day = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 12 | my $month = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 12 | ▶ | if(m#^\d+\.\d+$#) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | { # XX.YY and X.Y is in the format day.month | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 6 | $day =~ s/(\d+).*/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | $month =~ s#^\d+\.(\d+)\.?$#$1#; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | elsif (m#^\d+/\d+$#) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | { # XX/YY and X/Y is in the format month/day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 6 | $month =~ s/(\d+).*/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 6 | $day =~ s#^\d+/(\d+)\.?$#$1#; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 12 | $month--; # The month in the holiday file is 1-12, we use 0-11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 12 | $CreativeParser{MonthDay} = "$month-$day"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | elsif (/^(january|february|march|april|may|june|july|august|september|october|november|december)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | { # Which month it occurs in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 30 | $CreativeParser{IsMonth} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | elsif (/^plus$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | { # If the next number should be added to a NumericYDay value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 12 | $CreativeParser{NextIs} = 'add'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | elsif (/^minus$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | { # If the next number should be subtracted to a NumericYDay value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 6 | $CreativeParser{NextIs} = 'sub'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | elsif (/^length$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | { # How long (in days) it lasts. FIXME: is currently ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | $CreativeParser{NextIs} = 'length'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | elsif (/^easter$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | { # The day of easter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 18 | $CreativeParser{AddEaster} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | elsif (/^weekend$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | { # Malplaced weekend keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $HolidayType = 'red'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | elsif (/^\d+$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | { # Any other number, see below for parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 30 | ▶ | $self->_SyntaxError($LineNo, $File, 'Unreasonably high number', 'Ignoring the number. This might give weird results') and next if $_ > 365; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$_ > 365 && ($self->_SyntaxError($LineNo, $File, 'Unreasonably high number', 'Ignoring the number. This might give weird results') && (next))
$self->_SyntaxError($LineNo, $File, "Unreasonably high number", "Ignoring the number. This might give weird results") and next
MC/DC0%0/2
$_ > 365 && ($self->_SyntaxError($LineNo, $File, 'Unreasonably high number', 'Ignoring the number. This might give weird results') && (next))
$_ > 365
$self->_SyntaxError($LineNo, $File, "Unreasonably high number", "Ignoring the number. This might give weird results")
Truth table33%1/3
A && B
A= $_ > 365B= $self->_SyntaxError($LineNo, $File, "Unreasonably high number", "Ignoring the number. This might give weird results")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # If NextIs is not defined then it's a DateNumeric | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 30 | ▶ | unless(defined($CreativeParser{NextIs}) and $CreativeParser{NextIs}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $CreativeParser{"NextIs"} and $CreativeParser{"NextIs"}
MC/DC50%1/2
defined $CreativeParser{"NextIs"} and $CreativeParser{"NextIs"}
defined $CreativeParser{"NextIs"}
$CreativeParser{"NextIs"}
Truth table66%2/3
A and B
A= defined $CreativeParser{"NextIs"}B= $CreativeParser{"NextIs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 12 | $CreativeParser{DateNumeric} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 12 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # Add to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 18 | ▶ | if($CreativeParser{NextIs} eq 'add') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 12 | ▶ | if(defined($CreativeParser{AddDays})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $CreativeParser{AddDays} = $CreativeParser{AddDays} + $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 12 | $CreativeParser{AddDays} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # Subtract from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | elsif ($CreativeParser{NextIs} eq 'sub') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 6 | ▶ | if(defined($CreativeParser{SubtDays})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | $CreativeParser{SubtDays} = $CreativeParser{SubtDays} + $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 6 | $CreativeParser{SubtDays} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # How long should it last? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | elsif ($CreativeParser{NextIs} eq 'length') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | if(defined($CreativeParser{Length})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | $self->_SyntaxError($LineNo, $File, 'Multiple length statements', "Ignoring \"$_\""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | $CreativeParser{Length} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | elsif (/^(before|after)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | { # If a day should be before or after a certain day/date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 6 | $CreativeParser{BeforeOrAfter} = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | elsif (/^every$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 6 | $CreativeParser{Every} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | elsif (/^(in|on|days|day)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | { # Ignored, just keywords for easier human parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 96 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $self->_SyntaxError($LineNo, $File, "Unrecognized keyword \"$_\"", 'Ignoring it. This might cause calculation mistakes! Consider using a combination of other keywords or report this as a bug to the author of this parser if you\'re certain the keyword should be supported'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | # ================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | # Finalize the interpretation and add it to $self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # ================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 60 | $CreativeParser{HolidayType} = $HolidayType; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 60 | $CreativeParser{name} = $HolidayName; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 60 | $self->_parsed->{$LineNo} = \%CreativeParser; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 6 | close($HolidayFile); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | # End of Date::HolidayParser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||