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

(-)a/C4/Serials.pm (-25 / +48 lines)
Lines 2294-2310 sub GetFictiveIssueNumber { Link Here
2294
            ($wkno, $year) = Week_of_Year($year, $month, $day);
2294
            ($wkno, $year) = Week_of_Year($year, $month, $day);
2295
            my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day);
2295
            my ($fa_wkno, $fa_yr) = Week_of_Year($fa_year, $fa_month, $fa_day);
2296
            $delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2296
            $delta = ($fa_yr == $year) ? ($wkno - $fa_wkno) : ( ($year-$fa_yr-1)*52 + (52-$fa_wkno+$wkno) );
2297
        } elsif($unit eq 'month') {
2297
2298
            $delta = ($fa_year == $year)
2298
        } elsif( $unit eq 'month' || $unit eq 'year' ) {
2299
                   ? ($month - $fa_month)
2299
            $delta = _delta_units( [$fa_year, $fa_month, $fa_day], [$year, $month, $day], $unit );
2300
                   : ( ($year-$fa_year-1)*12 + (12-$fa_month+$month) );
2301
        } elsif( $unit eq 'year' ) {
2302
            ( $delta ) = N_Delta_YMD( $fa_year, $fa_month, $fa_day, $year, $month, $day );
2303
            if( $frequency->{issuesperunit} > 1 ) {
2300
            if( $frequency->{issuesperunit} > 1 ) {
2304
                $issueno = 1 + $delta * $frequency->{'issuesperunit'};
2301
                $issueno = 1 + $delta * $frequency->{'issuesperunit'};
2305
                my @fa_upd = Add_Delta_YM( $fa_year, $fa_month, $fa_day, $delta, 0 );
2302
                # Now calculate issues within last (incomplete) unit
2306
                $delta = Delta_Days( @fa_upd, $year, $month, $day );
2303
                $delta = Delta_Days(
2307
                my $incr = int( 365 / $frequency->{issuesperunit} );
2304
                    Add_Delta_YM( $fa_year, $fa_month, $fa_day,
2305
                        $unit eq 'month' ? ( 0, $delta ) : ( $delta, 0 )),
2306
                    $year, $month, $day );
2307
                my $incr = $unit eq 'month' ? 30 : 365;
2308
                $incr = int( $incr / $frequency->{issuesperunit} );
2308
                if( $incr > 0 ) {
2309
                if( $incr > 0 ) {
2309
                    $delta = int( $delta / $incr );
2310
                    $delta = int( $delta / $incr );
2310
                    $delta = $delta < $frequency->{issuesperunit} ? $delta : $frequency->{issuesperunit} - 1;
2311
                    $delta = $delta < $frequency->{issuesperunit} ? $delta : $frequency->{issuesperunit} - 1;
Lines 2327-2332 sub GetFictiveIssueNumber { Link Here
2327
    return $issueno;
2328
    return $issueno;
2328
}
2329
}
2329
2330
2331
sub _delta_units {
2332
# wrapper around N_Delta_YMD
2333
# Note that N_Delta_YMD returns 29 days between e.g. 22-2-72 and 22-3-72
2334
# while we expect 1 month.
2335
    my ( $date1, $date2, $unit ) = @_;
2336
    my @delta = N_Delta_YMD( @$date1, @$date2 );
2337
    if( $delta[2] > 27 ) {
2338
        # Check if we could add a month
2339
        my @jump = Add_Delta_YM( @$date1, $delta[0], 1 + $delta[1] );
2340
        if( Delta_Days( @jump, @$date2 ) >= 0 ) {
2341
            $delta[1]++;
2342
        }
2343
    }
2344
    if( $delta[1] >= 12 ) {
2345
        $delta[0]++;
2346
        $delta[1] -= 12;
2347
    }
2348
    # if unit is year, we only return full years
2349
    return $unit eq 'month' ? $delta[0] * 12 + $delta[1] : $delta[0];
2350
}
2351
2330
sub _get_next_date_day {
2352
sub _get_next_date_day {
2331
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2353
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2332
2354
Lines 2368-2391 sub _get_next_date_week { Link Here
2368
sub _get_next_date_month {
2390
sub _get_next_date_month {
2369
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2391
    my ($subscription, $freqdata, $year, $month, $day) = @_;
2370
2392
2371
    my $fa_day;
2393
    my @newissue; # ( yy, mm, dd )
2372
    (undef, undef, $fa_day) = split /-/, $subscription->{firstacquidate};
2394
    my $delta_days = int( 30 / $freqdata->{issuesperunit} );
2373
2395
2374
    if ($subscription->{countissuesperunit} + 1 > $freqdata->{issuesperunit}){
2396
    if( $freqdata->{issuesperunit} == 1 ) {
2375
        $subscription->{countissuesperunit} = 1;
2397
        # Add full months
2376
        ($year,$month,$day) = Add_Delta_YM($year,$month,$day, 0,
2398
        @newissue = Add_Delta_YM(
2377
            $freqdata->{unitsperissue});
2399
            $year, $month, $day, 0, $freqdata->{"unitsperissue"} );
2378
        my $days_in_month = Days_in_Month($year, $month);
2400
    } elsif ( $subscription->{countissuesperunit} < $freqdata->{issuesperunit} ) {
2379
        $day = $fa_day <= $days_in_month ? $fa_day : $days_in_month;
2401
        # Add rounded number of days based on frequency.
2380
    } else {
2402
        @newissue = Add_Delta_Days( $year, $month, $day, $delta_days );
2381
        # Try to guess the next day in month
2382
        my $days_in_month = Days_in_Month($year, $month);
2383
        my $delta_days = int(($days_in_month - ($fa_day - 1)) / $freqdata->{issuesperunit});
2384
        ($year,$month,$day) = Add_Delta_Days($year, $month, $day, $delta_days);
2385
        $subscription->{countissuesperunit}++;
2403
        $subscription->{countissuesperunit}++;
2404
    } else {
2405
        # We finished a cycle of issues within a unit.
2406
        # Subtract delta * (issues - 1), add 1 month
2407
        @newissue = Add_Delta_Days( $year, $month, $day,
2408
            -$delta_days * ($freqdata->{issuesperunit} - 1) );
2409
        @newissue = Add_Delta_YM( @newissue, 0, 1 );
2410
        $subscription->{countissuesperunit} = 1;
2386
    }
2411
    }
2387
2412
    return @newissue;
2388
    return ($year, $month, $day);
2389
}
2413
}
2390
2414
2391
sub _get_next_date_year {
2415
sub _get_next_date_year {
2392
- 

Return to bug 18607