# NOTE: Derived from web_diary_dir/lib/TDS/Collection.pm.
# Changes made here will be lost when autosplit again.
# See AutoSplit.pm.
package TDS::Collection;

#line 375 "web_diary_dir/lib/TDS/Collection.pm (autosplit into web_diary_dir/lib/auto/TDS/Collection/pickup_neighbour.al)"
sub pickup_neighbour ($$$$$$)
{
    my ($self, $year, $month, $day, $prev_num, $next_num) = @_;
    
    my $min_day = $day - $prev_num;
    my $max_day = $day + $next_num;
    
    my @files;
    my $date = new DateTime::Date(year=>$year, month=>$month);
#    my $min_date = new DateTime::Date(year=>$year, month=>$month, day=>$day);
#    my $max_date = new DateTime::Date(year=>$year, month=>$month, day=>$day);
    
#    $min_date -= $prev_num;
#    $max_date += $next_num;

    # 前月にまたがる
    if ($min_day < 1){
	my $prev_date = new DateTime::Date(year=>$year, month=>$month, day=>$day);
	$prev_date -= '1M';
	
	my $days_month = $prev_date->DaysMonth;
	@files = $self->pickup_files($prev_date->year,
				   $prev_date->month,
				   $days_month + $min_day,
				   $days_month);
	$min_day = 1;
    }
    push(@files, $self->pickup_files($date->year,
				   $date->month,
				   $min_day, $max_day));
    # 次の月にまたがる
    if ($max_day > $date->DaysMonth){
	my $next_date = new DateTime::Date(year=>$year, month=>$month, day=>$day);

	my $days_month = $date->DaysMonth;
	$next_date += '1M';
	push(@files, $self->pickup_files($next_date->year,
					 $next_date->month,
					 1,
					 $max_day-$days_month));
    }
    return @files;
}

# end of TDS::Collection::pickup_neighbour
1;
