The issue number calculation is based on subscription frequency, first acquisition
date, and $publisheddate.
+Returns undef when called for irregular frequencies.
+
The routine is used to skip irregularities when calculating the next issue
date (in GetNextDate) or the next issue number (in GetNextSeq).
my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'});
my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef;
- my $issueno = 0;
+ return if !$unit;
+ my $issueno;
- if($unit) {
- my ($year, $month, $day) = split /-/, $publisheddate;
- my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'};
- my $wkno;
- my $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
+ my ( $year, $month, $day ) = split /-/, $publisheddate;
+ my ( $fa_year, $fa_month, $fa_day ) = split /-/, $subscription->{'firstacquidate'};
+ my $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
- if($frequency->{'unitsperissue'} == 1) {
- $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
- } else {
- # Assuming issuesperunit == 1
- $issueno = int( ($delta + $frequency->{'unitsperissue'}) / $frequency->{'unitsperissue'} );
- }
+ if( $frequency->{'unitsperissue'} == 1 ) {
+ $issueno = $delta * $frequency->{'issuesperunit'} + $subscription->{'countissuesperunit'};
+ } else { # issuesperunit == 1
+ $issueno = 1 + int( $delta / $frequency->{'unitsperissue'} );
}
return $issueno;
}
sub _delta_units {
my ( $date1, $date2, $unit ) = @_;
+ # date1 and date2 are array refs in the form [ yy, mm, dd ]
if( $unit eq 'day' ) {
return Delta_Days( @$date1, @$date2 );
periodicity => $freq_irr,
firstacquidate => '1972-02-07',
};
- is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), 0, 'Irregular: should be zero' );
- is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), 0, 'Irregular: still zero' );
+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
};
subtest 'Tests for yearly frequencies' => sub {