Bugzilla – Attachment 36924 Details for
Bug 12671
Guess next serial date when there are several issues per unit
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12671: Refactor GetNextDate
Bug-12671-Refactor-GetNextDate.patch (text/plain), 9.68 KB, created by
Julian Maurice
on 2015-03-16 11:03:43 UTC
(
hide
)
Description:
Bug 12671: Refactor GetNextDate
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2015-03-16 11:03:43 UTC
Size:
9.68 KB
patch
obsolete
>From e5126d4c4cf2f52ce1fe65f49c73b0ab8c301d9b Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Mon, 21 Jul 2014 17:06:33 +0200 >Subject: [PATCH] Bug 12671: Refactor GetNextDate > >A much needed refactoring. Thanks for seeing the effort through. >Signed-off-by: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >--- > C4/Serials.pm | 172 ++++++++++++++++++++++++++++++---------------------------- > 1 file changed, 89 insertions(+), 83 deletions(-) > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index 538d4bd..505cebc 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -2430,6 +2430,77 @@ sub GetFictiveIssueNumber { > return $issueno; > } > >+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 { >+ $subscription->{'countissuesperunit'}++; >+ } >+ >+ return ($year, $month, $day); >+} >+ >+sub _get_next_date_week { >+ my ($subscription, $freqdata, $year, $month, $day) = @_; >+ >+ my ($wkno, $yr) = Week_of_Year($year, $month, $day); >+ >+ if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >+ $subscription->{'countissuesperunit'} = 1; >+ $wkno += $freqdata->{"unitsperissue"}; >+ if($wkno > 52){ >+ $wkno = $wkno % 52; >+ $yr++; >+ } >+ my $dow = Day_of_Week($year, $month, $day); >+ ($year,$month,$day) = Monday_of_Week($wkno, $yr); >+ if($freqdata->{'issuesperunit'} == 1) { >+ ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); >+ } >+ } else { >+ $subscription->{'countissuesperunit'}++; >+ } >+ >+ return ($year, $month, $day); >+} >+ >+sub _get_next_date_month { >+ my ($subscription, $freqdata, $year, $month, $day) = @_; >+ >+ if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >+ $subscription->{'countissuesperunit'} = 1; >+ ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); >+ unless($freqdata->{'issuesperunit'} == 1) { >+ $day = 1; # Jumping to the first day of month, because we don't know what day is expected >+ } >+ } else { >+ $subscription->{'countissuesperunit'}++; >+ } >+ >+ return ($year, $month, $day); >+} >+ >+sub _get_next_date_year { >+ my ($subscription, $freqdata, $year, $month, $day) = @_; >+ >+ if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >+ $subscription->{'countissuesperunit'} = 1; >+ ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); >+ unless($freqdata->{'issuesperunit'} == 1) { >+ # Jumping to the first day of year, because we don't know what day is expected >+ $month = 1; >+ $day = 1; >+ } >+ } else { >+ $subscription->{'countissuesperunit'}++; >+ } >+ >+ return ($year, $month, $day); >+} >+ > =head2 GetNextDate > > $resultdate = GetNextDate($publisheddate,$subscription) >@@ -2480,107 +2551,41 @@ sub GetNextDate { > my $unit = lc $freqdata->{'unit'}; > if ($unit eq 'day') { > while ($irregularities{$issueno}) { >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{'unitsperissue'} ); >- $subscription->{'countissuesperunit'} = 1; >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_day($subscription, >+ $freqdata, $year, $month, $day); > $issueno++; > } >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- ($year,$month,$day) = Add_Delta_Days($year,$month, $day , $freqdata->{"unitsperissue"} ); >- $subscription->{'countissuesperunit'} = 1; >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_day($subscription, $freqdata, >+ $year, $month, $day); > } > elsif ($unit eq 'week') { >- my ($wkno, $yr) = Week_of_Year($year, $month, $day); > while ($irregularities{$issueno}) { >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- $wkno += $freqdata->{"unitsperissue"}; >- if($wkno > 52){ >- $wkno = $wkno % 52; >- $yr++; >- } >- my $dow = Day_of_Week($year, $month, $day); >- ($year,$month,$day) = Monday_of_Week($wkno, $yr); >- if($freqdata->{'issuesperunit'} == 1) { >- ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_week($subscription, >+ $freqdata, $year, $month, $day); > $issueno++; > } >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- $wkno += $freqdata->{"unitsperissue"}; >- if($wkno > 52){ >- $wkno = $wkno % 52 ; >- $yr++; >- } >- my $dow = Day_of_Week($year, $month, $day); >- ($year,$month,$day) = Monday_of_Week($wkno, $yr); >- if($freqdata->{'issuesperunit'} == 1) { >- ($year, $month, $day) = Add_Delta_Days($year, $month, $day, $dow - 1); >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_week($subscription, >+ $freqdata, $year, $month, $day); > } > elsif ($unit eq 'month') { > while ($irregularities{$issueno}) { >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); >- unless($freqdata->{'issuesperunit'} == 1) { >- $day = 1; # Jumping to the first day of month, because we don't know what day is expected >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_month($subscription, >+ $freqdata, $year, $month, $day); > $issueno++; > } >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,$freqdata->{"unitsperissue"}); >- unless($freqdata->{'issuesperunit'} == 1) { >- $day = 1; # Jumping to the first day of month, because we don't know what day is expected >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_month($subscription, >+ $freqdata, $year, $month, $day); > } > elsif ($unit eq 'year') { > while ($irregularities{$issueno}) { >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); >- unless($freqdata->{'issuesperunit'} == 1) { >- # Jumping to the first day of year, because we don't know what day is expected >- $month = 1; >- $day = 1; >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_year($subscription, >+ $freqdata, $year, $month, $day); > $issueno++; > } >- if ($subscription->{'countissuesperunit'} + 1 > $freqdata->{'issuesperunit'}){ >- $subscription->{'countissuesperunit'} = 1; >- ($year,$month,$day) = Add_Delta_YM($year,$month,$day, $freqdata->{"unitsperissue"},0); >- unless($freqdata->{'issuesperunit'} == 1) { >- # Jumping to the first day of year, because we don't know what day is expected >- $month = 1; >- $day = 1; >- } >- } else { >- $subscription->{'countissuesperunit'}++; >- } >+ ($year, $month, $day) = _get_next_date_year($subscription, >+ $freqdata, $year, $month, $day); > } >+ > if ($updatecount){ > my $dbh = C4::Context->dbh; > my $query = qq{ >@@ -2591,6 +2596,7 @@ sub GetNextDate { > my $sth = $dbh->prepare($query); > $sth->execute($subscription->{'countissuesperunit'}, $subscription->{'subscriptionid'}); > } >+ > return sprintf("%04d-%02d-%02d", $year, $month, $day); > } > } >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12671
:
30291
|
30292
|
34658
|
34659
|
34660
|
36924
|
36925
|
36926
|
37340
|
37341
|
37342