From f65ca90b0f3d12a22c02918a37131b0c1ff8bd5e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 30 May 2017 16:44:46 +0200 Subject: [PATCH] Bug 18697: Fix date calculation for dayly frequencies in Serials The changes in _get_next_date_day are actually only cosmetic. The sub now reads exactly the same as its counterparts for other units, but the results are exactly the same as before. In GetFictiveIssueNumber we now call _delta_units for each type of unit. The two Delta_Days calls are moved to _delta_units. Note that this also is a cosmetic change; results should be exactly the same. Test plan: [1] Edit a subscription. Test predication pattern for some daily freq. [2] Run t/db_dependent/GetNextDate.t Signed-off-by: Marcel de Rooy Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Serials.pm | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 2f3cb2db7f..3a9b1d6cd6 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -2286,15 +2286,8 @@ sub GetFictiveIssueNumber { my ($year, $month, $day) = split /-/, $publisheddate; my ($fa_year, $fa_month, $fa_day) = split /-/, $subscription->{'firstacquidate'}; my $wkno; - my $delta; - - if($unit eq 'day') { - $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day); - } elsif($unit eq 'week') { - $delta = int( Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day) / 7); - } elsif( $unit eq 'month' || $unit eq 'year' ) { - $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit ); - } + 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 { @@ -2306,10 +2299,17 @@ sub GetFictiveIssueNumber { } sub _delta_units { -# wrapper around N_Delta_YMD -# Note that N_Delta_YMD returns 29 days between e.g. 22-2-72 and 22-3-72 -# while we expect 1 month. my ( $date1, $date2, $unit ) = @_; + + if( $unit eq 'day' ) { + return Delta_Days( @$date1, @$date2 ); + } elsif( $unit eq 'week' ) { + return int( Delta_Days( @$date1, @$date2 ) / 7 ); + } + + # In case of months or years, this is a wrapper around N_Delta_YMD. + # Note that N_Delta_YMD returns 29 days between e.g. 22-2-72 and 22-3-72 + # while we expect 1 month. my @delta = N_Delta_YMD( @$date1, @$date2 ); if( $delta[2] > 27 ) { # Check if we could add a month @@ -2329,14 +2329,24 @@ sub _delta_units { sub _get_next_date_day { my ($subscription, $freqdata, $year, $month, $day) = @_; - if ($subscription->{countissuesperunit} + 1 > $freqdata->{issuesperunit}){ - ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{unitsperissue} ); - $subscription->{countissuesperunit} = 1; - } else { + my @newissue; # ( yy, mm, dd ) + # We do not need $delta_days here, since it would be zero where used + + if( $freqdata->{issuesperunit} == 1 ) { + # Add full days + @newissue = Add_Delta_Days( + $year, $month, $day, $freqdata->{"unitsperissue"} ); + } elsif ( $subscription->{countissuesperunit} < $freqdata->{issuesperunit} ) { + # Add zero days + @newissue = ( $year, $month, $day ); $subscription->{countissuesperunit}++; + } else { + # We finished a cycle of issues within a unit. + # No subtraction of zero needed, just add one day + @newissue = Add_Delta_Days( $year, $month, $day, 1 ); + $subscription->{countissuesperunit} = 1; } - - return ($year, $month, $day); + return @newissue; } sub _get_next_date_week { -- 2.39.5