@@ -, +, @@ Serials For example: 1 iss/y, 1 iss/2y, 5 iss/y. --- C4/Serials.pm | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -2270,6 +2270,9 @@ depending on how many rows are in serial table. The issue number calculation is based on subscription frequency, first acquisition date, and $publisheddate. +The routine is used to skip irregularities when calculating the next issue +date (in GetNextDate) or the next issue number (in GetNextSeq). + =cut sub GetFictiveIssueNumber { @@ -2297,6 +2300,10 @@ sub GetFictiveIssueNumber { : ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) ); } elsif($unit eq 'year') { $delta = $year - $fa_year; + if( $frequency->{issuesperunit} > 1 ) { + $delta-- if $month < $fa_month || + ( $month == $fa_month && $day < $fa_day ); + } } if($frequency->{'unitsperissue'} == 1) { $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'}; @@ -2372,23 +2379,38 @@ sub _get_next_date_month { sub _get_next_date_year { my ($subscription, $freqdata, $year, $month, $day) = @_; - my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{firstacquidate}; + my (undef, $fa_month, $fa_day) = split /-/, $subscription->{firstacquidate}; - if ($subscription->{countissuesperunit} + 1 > $freqdata->{issuesperunit}){ - $subscription->{countissuesperunit} = 1; - ($year) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); - $month = $fa_month; - my $days_in_month = Days_in_Month($year, $month); - $day = $fa_day <= $days_in_month ? $fa_day : $days_in_month; + my @newissue; # ( yy, mm, dd ) + if( $freqdata->{issuesperunit} == 1 ) { # adding years + @newissue = Add_Delta_YM( + $year, $month, $day, $freqdata->{"unitsperissue"}, 0 ); } else { - # Try to guess the next day in year - my $days_in_year = Days_in_Year($year,12); #Sum the days of all the months of this year - my $delta_days = int(($days_in_year - ($fa_day - 1)) / $freqdata->{issuesperunit}); - ($year,$month,$day) = Add_Delta_Days($year, $month, $day, $delta_days); - $subscription->{countissuesperunit}++; - } + # Add rounded number of days based on frequency. + # We always use the same number of days (calculated with 365.25). + my $delta_days = int( 365.25 / $freqdata->{issuesperunit} ); + @newissue = Add_Delta_Days( $year, $month, $day, $delta_days ); - return ($year, $month, $day); + # Did we finish a cycle of issues within a unit? Correct rounding. + if( $subscription->{countissuesperunit} >= $freqdata->{issuesperunit} ) + { + $subscription->{countissuesperunit} = 1; + my $newyr = $newissue[0]; + $newyr++ if $fa_month < $newissue[1]; + my $days_in_month = Days_in_Month($newyr, $fa_month); + $fa_day = $days_in_month if $fa_day > $days_in_month; + # If newissue is older than the firstacqui based date, and + # difference <= number of issues per unit, we accept + # the firstacqui based date. + # Note: We use <= because of leap years! + $delta_days = Delta_Days( @newissue, $newyr, $fa_month, $fa_day ); + @newissue = ( $newyr, $fa_month, $fa_day ) + if $delta_days > 0 && $delta_days <= $freqdata->{issuesperunit}; + } else { + $subscription->{countissuesperunit}++; + } + } + return @newissue; } =head2 GetNextDate --