View | Details | Raw Unified | Return to bug 18697
Collapse All | Expand All

(-)a/C4/Serials.pm (-22 / +36 lines)
Lines 2291-2300 sub GetFictiveIssueNumber { Link Here
2291
        if($unit eq 'day') {
2291
        if($unit eq 'day') {
2292
            $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day);
2292
            $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day);
2293
        } elsif($unit eq 'week') {
2293
        } elsif($unit eq 'week') {
2294
            ($wkno, $year) = Week_of_Year($year, $month, $day);
2294
            $delta = Delta_Days($fa_year, $fa_month, $fa_day, $year, $month, $day);
2295
            my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day);
2295
            if( $frequency->{issuesperunit} > 1 ) {
2296
            $delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2296
                $issueno = 1 + int( $delta / 7) * $frequency->{'issuesperunit'};
2297
2297
                # Now calculate issues within last (incomplete) unit
2298
                $delta = $delta % 7;
2299
                my $incr = $unit eq 'week' ? 7 : 1;
2300
                $incr = int( $incr / $frequency->{issuesperunit} );
2301
                if( $incr > 0 ) {
2302
                    $delta = int( $delta / $incr );
2303
                    $delta = $delta < $frequency->{issuesperunit} ? $delta : $frequency->{issuesperunit} - 1;
2304
                } else {
2305
                    $delta = $frequency->{issuesperunit} - 1;
2306
                }
2307
                $issueno += $delta;
2308
            } else {
2309
                $delta = int( $delta / 7 );
2310
                $issueno = 1 + int( $delta / $frequency->{'unitsperissue'} );
2311
            }
2312
            return $issueno;
2298
        } elsif( $unit eq 'month' || $unit eq 'year' ) {
2313
        } elsif( $unit eq 'month' || $unit eq 'year' ) {
2299
            $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
2314
            $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
2300
            if( $frequency->{issuesperunit} > 1 ) {
2315
            if( $frequency->{issuesperunit} > 1 ) {
Lines 2365-2390 sub _get_next_date_day { Link Here
2365
sub _get_next_date_week {
2380
sub _get_next_date_week {
2366
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2381
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2367
2382
2368
    my ($wkno, $yr) = Week_of_Year($year, $month, $day);
2383
    my @newissue; # ( yy, mm, dd )
2369
    my $fa_dow = Day_of_Week(split /-/, $subscription->{firstacquidate});
2384
    my $delta_days = int( 7 / $freqdata->{issuesperunit} );
2370
2385
2371
    if ($subscription->{countissuesperunit} + 1 > $freqdata->{issuesperunit}){
2386
    if( $freqdata->{issuesperunit} == 1 ) {
2372
        $subscription->{countissuesperunit} = 1;
2387
        # Add full weeks (of 7 days)
2373
        $wkno += $freqdata->{unitsperissue};
2388
        @newissue = Add_Delta_Days(
2374
        if($wkno > 52){
2389
            $year, $month, $day, 7 * $freqdata->{"unitsperissue"} );
2375
            $wkno = $wkno % 52;
2390
    } elsif ( $subscription->{countissuesperunit} < $freqdata->{issuesperunit} ) {
2376
            $yr++;
2391
        # Add rounded number of days based on frequency.
2377
        }
2392
        @newissue = Add_Delta_Days( $year, $month, $day, $delta_days );
2378
        ($year,$month,$day) = Monday_of_Week($wkno, $yr);
2379
        ($year,$month,$day) = Add_Delta_Days($year, $month, $day, $fa_dow - 1);
2380
    } else {
2381
        # Try to guess the next day of week
2382
        my $delta_days = int((7 - ($fa_dow - 1)) / $freqdata->{issuesperunit});
2383
        ($year,$month,$day) = Add_Delta_Days($year, $month, $day, $delta_days);
2384
        $subscription->{countissuesperunit}++;
2393
        $subscription->{countissuesperunit}++;
2394
    } else {
2395
        # We finished a cycle of issues within a unit.
2396
        # Subtract delta * (issues - 1), add 1 week
2397
        @newissue = Add_Delta_Days( $year, $month, $day,
2398
            -$delta_days * ($freqdata->{issuesperunit} - 1) );
2399
        @newissue = Add_Delta_Days( @newissue, 7 );
2400
        $subscription->{countissuesperunit} = 1;
2385
    }
2401
    }
2386
2402
    return @newissue;
2387
    return ($year, $month, $day);
2388
}
2403
}
2389
2404
2390
sub _get_next_date_month {
2405
sub _get_next_date_month {
2391
- 

Return to bug 18697