App-calx

 view release on metacpan or  search on metacpan

lib/App/calx.pm  view on Meta::CPAN

        $start_month = $args{month} // 1;
        $end_month = $start_month + ($args{months} // 1) - 1;
    }

    for my $year (@years) {
        my $start_mon2 = $year == $years[0] ? $start_month : 1;
        my $end_mon2 = $year == $years[-1] ? $end_month : 12;

        unless ($start_mon2 == $end_mon2) {
            # show multiples of 3 months instead of just 2 months
            if (($start_mon2-1) % 3) {
                $start_mon2 = int(($start_mon2-1)/3)*3+1;
            }
            if ($end_mon2 % 3) {
                $end_mon2 = int(($end_mon2+2)/3)*3;
            }
        }

        my $year_has_been_printed;
        my @moncals;
        for my $mon ($start_mon2 .. $end_mon2) {
            my %margs = (
                caldates_modules => $args{caldates_modules},
                highlight_today => ($args{highlight_today} // 1),
            );
            if ($start_mon2 == 1 && $end_mon2 == 12) {
                $margs{show_year_in_title} = 0;
                push @lines, _center(64, $year) unless $year_has_been_printed++;
            }
            $margs{show_prev_month_days} = 0 unless $start_mon2 == $end_mon2;
            $margs{show_next_month_days} = 0 unless $start_mon2 == $end_mon2;

            if ($dates) {
                $margs{dates} = [
                    grep { $_->{month} == $mon && $_->{year} == $year }
                    @$dates];
            }

            push @moncals, gen_monthly_calendar(
                month=>$mon, year=>$year, time_zone=>$tz, %margs);
        } # for month

        # group per three months
        my @hol = map {@{ $_->[1] }} @moncals;
        my $l = max(map {@$_+0} map {$_->[0]} @moncals);
        my $i = 0;
        my $j = @moncals;
        while (1) {
            for (0..$l-1) {
                push @lines,
                    sprintf("%s %s %s",
                            _rpad(21, $moncals[$i+0][0][$_]//""),
                            _rpad(21, $moncals[$i+1][0][$_]//""),
                            _rpad(21, $moncals[$i+2][0][$_]//""));
            }
            last if $i+3 >= $j;
            $i += 3;
            push @lines, "";
        }

        # print legends
        for my $i (0..@hol-1) {
            if ($hol[1]{module}) {
                my @notes = ($hol[$i]{module});
                push @notes, @{$hol[$i]{tags}} if $hol[1]{tags};
                push @lines, "" if $i == 0;
                push @lines, sprintf("%s%2d %s = %s\e[0m",
                                     ansifg(assign_rgb_light_color($hol[$i]{module})),
                                     $hol[$i]{day}, $short_month_names->[$hol[$i]{month}-1],
                                     "$hol[$i]{summary} (".join(", ", @notes).")",
                                 );
            }
        }

    } # for year

    [200, "OK", join("\n", @lines)];
}

1;
# ABSTRACT: Display a calendar, with highlighted dates

__END__

=pod

=encoding UTF-8

=head1 NAME

App::calx - Display a calendar, with highlighted dates

=head1 VERSION

This document describes version 0.009 of App::calx (from Perl distribution App-calx), released on 2023-06-22.

=head1 SYNOPSIS

 # See calx script provided in this distribution

=head1 DESCRIPTION

=head1 FUNCTIONS


=head2 gen_calendar

Usage:

 gen_calendar(%args) -> [$status_code, $reason, $payload, \%result_meta]

Generate one or more monthly calendars in 3-column format.

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<caldates_modules> => I<array[perl::calendar::dates::modname]>



( run in 1.729 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )