From bbf1311078ccc9c26de91a1228c1396ca879bd8b Mon Sep 17 00:00:00 2001 From: djfiander Date: Thu, 25 Jun 2009 01:50:12 +0000 Subject: [PATCH] Now supports generating dates of combined issues (eg, "May/June"). More test cases are needed, though. git-svn-id: svn://svn.open-ils.org/ILS/trunk@13462 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/MFHD/Caption.pm | 36 ++++++++++++++++++++-- .../src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm index fef486df71..a6232b4ed3 100755 --- a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm @@ -336,8 +336,8 @@ sub next_date { my @keys = @_; my @cur; my @new; + my @newend; # only used for combined issues my $incr; - my @candidate; my $reg = $self->{_mfhdc_REGULARITY}; my $pattern = $self->{_mfhdc_PATTERN}; @@ -368,7 +368,8 @@ sub next_date { } foreach my $pat (@pats) { - @candidate = $genfunc->($pat, @cur); + my @candidate = $genfunc->($pat, @cur); + while ($self->is_omitted(@candidate)) { # printf("# pubpat omitting date '%s'\n", # join('/', @candidate)); @@ -386,6 +387,37 @@ sub next_date { } } } + + # Now check for combined issues, like "May/June" + foreach my $combpat (@{$pattern->{y}->{c}}) { + my $chroncode = substr($combpat, 0, 1); + my $genfunc = MFHD::Date::generator($chroncode); + my @pats = split(/,/, substr($combpat, 1)); + + foreach my $combined (@pats) { + my ($start, $end) = split('/', $combined, 2); + my @candidate = $genfunc->($start, @cur); + + # We don't need to check for omitted issues because + # combined issues are always published. OR ARE THEY???? + if (!defined($new[0]) + || !on_or_after($candidate[0], $candidate[1], $new[0], $new[1])) { + # Haven't found a next issue at all yet, or + # this one is before the best guess so far + @new = @candidate; + @newend = $genfunc->($end, @cur); + } + } + } + + if (defined($newend[0])) { + # The best match was a combined issue + foreach my $i (0..$#new) { + # don't combine identical fields + next if $new[$i] eq $newend[$i]; + $new[$i] .= '/' . $newend[$i]; + } + } } else { # There is no $y publication pattern defined, so use # the $w frequency to figure out the next date diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t index 95d719adc3..6f26524374 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t @@ -213,7 +213,7 @@ __END__ 245 00 $aBimonthly, published 5 times with combined summer issue: Feb, Apr, June/Aug, Oct, Dec 853 20 $820$av.$bno.$u5$vr$i(year)$j(month)$wb$x02$ypm02,04,10,12$ycm06/08 -863 41 $820.1$a1$b2$i1990$j04$x|a1|b3|i1990|j06/08$zTODO From Apr to Jun/Aug +863 41 $820.1$a1$b2$i1990$j04$x|a1|b3|i1990|j06/08$zFrom Apr to Jun/Aug 863 41 $820.2$a1$b3$i1990$j06/08$x|a1|b4|i1990|j10$zFrom Jun/Aug to Oct 863 41 $820.3$a1$b5$i1990$j12$x|a2|b1|i1991|j02$zWrap at end of year/vol. -- 2.11.0