App-calx
    
    
  
  
  
view release on metacpan or search on metacpan
	- [bugfix] Trap exception from get_entries() (i.e. when dates from
	  year later than latest supported year is requested).
0.003   2019-02-13  Released-By: PERLANCAR
	- Add option -a (get dates from all installed Calendar::Dates::*
	  modules).
	- [ux] Show calendar date module name for each entry.
0.002   2019-02-13  Released-By: PERLANCAR
	- Show each calendar with a different color.
0.001   2019-02-13  Released-By: PERLANCAR
        - First release.
{
   "abstract" : "Display a calendar, with highlighted dates",
   "author" : [
      "perlancar <perlancar@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.028, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'Display a calendar, with highlighted dates'
author:
  - 'perlancar <perlancar@cpan.org>'
build_requires:
  File::Spec: '0'
  IO::Handle: '0'
  IPC::Open3: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.028.
use strict;
use warnings;
use 5.010001;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
  "ABSTRACT" => "Display a calendar, with highlighted dates",
  "AUTHOR" => "perlancar <perlancar\@cpan.org>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME" => "App-calx",
  "EXE_FILES" => [
    "script/calx"
  ],
  "LICENSE" => "perl",
  "MIN_PERL_VERSION" => "5.010001",
NAME
    App::calx - Display a calendar, with highlighted dates
VERSION
    This document describes version 0.009 of App::calx (from Perl
    distribution App-calx), released on 2023-06-22.
SYNOPSIS
     # See calx script provided in this distribution
DESCRIPTION
FUNCTIONS
  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):
    *   caldates_modules => *array[perl::calendar::dates::modname]*
        (No description)
    *   dates => *array[hash]*
        (No description)
    *   highlight_today => *bool* (default: 1)
        (No description)
    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra
    information, much like how HTTP response headers provide additional
    metadata.
    Return value: (any)
  gen_monthly_calendar
    Usage:
     gen_monthly_calendar(%args) -> any
    Generate a single month calendar.
    Return [\@lines, \@hol]
    This function is not exported.
    Arguments ('*' denotes required arguments):
    *   caldates_modules => *array[perl::calendar::dates::modname]*
        (No description)
    *   dates => *array[hash]*
        (No description)
    *   highlight_today => *bool* (default: 1)
        (No description)
lib/App/calx.pm view on Meta::CPAN
our $VERSION = '0.009'; # VERSION
# XXX use locale
my $month_names = [qw(January February March April May June July August September October November December)];
my $short_month_names = [qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)];
our %SPEC;
$SPEC{':package'} = {
    v => 1.1,
    summary => 'Display a calendar, with highlighted dates',
};
sub _center {
    my ($w, $text) = @_;
    my $tw = length($text);
    sprintf("%s%s%s",
            (" " x int(($w-$tw)/2)),
            $text,
            (" " x int(($w-$tw)/2)),
        );
}
sub _rpad {
    my ($w, $text) = @_;
    sprintf("%s%s", $text, " " x ($w-ta_length($text)));
}
$SPEC{gen_monthly_calendar} = {
    v => 1.1,
    summary => 'Generate a single month calendar',
    description => <<'_',
Return [\@lines, \@hol]
_
    args => {
        month => {
            schema => ['int*' => between => [1, 12]],
            req => 1,
        },
lib/App/calx.pm view on Meta::CPAN
        highlight_today => {
            schema => [bool => default => 1],
        },
        time_zone => {
            schema => 'str*',
        },
        dates => {
            schema => ['array*', of=>'hash*'],
        },
        caldates_modules => {
            schema => ['array*', of=>'perl::calendar::dates::modname*'],
            cmdline_aliases => {c=>{}},
        },
    },
    "x.perinci.sub.wrapper.disable_validate_args" => 1,
    result_naked => 1,
};
sub gen_monthly_calendar {
    my %args = @_;
    my $m = $args{month};
    my $y = $args{year};
    my @lines;
    my $tz = $args{time_zone} // $ENV{TZ} // "UTC";
    my $dt  = DateTime->new(year=>$y, month=>$m, day=>1, time_zone=>$tz);
    my $dtl = DateTime->last_day_of_month(year=>$y, month=>$m, time_zone=>$tz);
    my $dt_today = DateTime->today(time_zone=>$tz);
lib/App/calx.pm view on Meta::CPAN
        $dow = $dt->day_of_week - 1; $dow = 7 if $dow == 0;
        for my $i ($dow+1..7) {
            $lines[-1] .= sprintf("%s%2d \e[0m", ansifg("404040"), $dt->day);
            $dt->add(days => 1);
        }
    }
    return [\@lines, $hol];
}
$SPEC{gen_calendar} = {
    v => 1.1,
    summary => 'Generate one or more monthly calendars in 3-column format',
    args => {
        months => {
            schema => ['int*', min=>1, max=>12, default=>1],
        },
        year => {
            schema => ['int*'],
        },
        month => {
            summary => 'The first month',
            schema => ['int*'],
lib/App/calx.pm view on Meta::CPAN
            schema => [bool => default => 1],
        },
        time_zone => {
            schema => 'str*',
        },
        dates => {
            schema => ['array*', of=>'hash*'],
        },
        caldates_modules => {
            schema => ['array*', of=>['perl::calendar::dates::modname*']],
        },
    },
    "x.perinci.sub.wrapper.disable_validate_args" => 1,
    args_rels => {
        choose_one => [qw/dates caldates_modules/],
        req_one => [qw/year dates/],
    },
};
sub gen_calendar {
    my %args = @_;
    my $dates = $args{dates};
    my @lines;
    my $tz = $args{time_zone} // $ENV{TZ} // "UTC";
    my @years;
    my ($start_month, $end_month);
    if ($dates && @$dates) {
        my ($min_date, $max_date);
lib/App/calx.pm view on Meta::CPAN
            }
            $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) {
lib/App/calx.pm view on Meta::CPAN
                                 );
            }
        }
    } # 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]>
(No description)
=item * B<dates> => I<array[hash]>
(No description)
=item * B<highlight_today> => I<bool> (default: 1)
(No description)
lib/App/calx.pm view on Meta::CPAN
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.
Return value:  (any)
=head2 gen_monthly_calendar
Usage:
 gen_monthly_calendar(%args) -> any
Generate a single month calendar.
Return [\@lines, \@hol]
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<caldates_modules> => I<array[perl::calendar::dates::modname]>
(No description)
=item * B<dates> => I<array[hash]>
(No description)
=item * B<highlight_today> => I<bool> (default: 1)
(No description)
script/calx view on Meta::CPAN
    $args{year}  = $dt->year;
}
if ($args{months} == 3) {
    $dt = DateTime->new(year=>$args{year}, month=>$args{month}//1, day=>1);
    $dt->subtract(months=>1);
    $args{month} = $dt->month;
    $args{year}  = $dt->year;
}
my $res = App::calx::gen_calendar(%args);
die $res->[1] unless $res->[0] == 200;
say $res->[2];
1;
# ABSTRACT: Display calendar, with highlighted dates
# PODNAME: calx
__END__
=pod
=encoding UTF-8
=head1 NAME
calx - Display calendar, with highlighted dates
=head1 VERSION
This document describes version 0.009 of calx (from Perl distribution App-calx), released on 2023-06-22.
=head1 SYNOPSIS
 # show calendar for the current month, with dates from Calendar::Dates::ID::Holiday
 % calx -c ID::Holiday
 # show calendar for the current month, with dates from Calendar::Dates::ID::Holiday and Calendar::Dates::SG::Holiday
 % calx -c ID::Holiday -c SD::Holiday
 # show calendar for the current month, with dates from all installed Calendar::Dates::* modules
 % calx -a
 # show calendar for the whole year
 % calx 2019 -c ID::Holiday
 # show calendar for a certain month and year
 % calx 2 2019 -c ID::Holiday
 # echo -e "2023-05-30\n2023-05-31\n2023-06-01\n" | calx
=head1 DESCRIPTION
This command provides a variant of B<cal> utility for displaying ASCII calendar
on the command-line. It focuses on highlighting certain dates. It currently
always starts the week at Monday and can get the list of dates from command-line
option (`--date`) or stdin or one or more L<Calendar::Dates>::* modules.
=head1 OPTIONS
 % calx [opts] [[month] year]
Most options follow B<cal>. Not all options from B<cal> are
supported/recognized. Some options are specific to B<calx>.
=head2 -1
Show a single month of calendar (the default).
=head2 -3
Show three months of calendar (previous, current, next).
=head2 -h
Turn off highlighting of today.
=head2 -y
Show one year (12 months) of calendar (the default if only year is specified).
=head2 -c MODULE+
Get dates from a L<Calendar::Dates> module (value is name of module without the
"Calendar::Dates::" prefix). Can be specified multiple times.
=head2 -a
Get dates from all installed C<Calendar::Dates::*> modules.
( run in 0.499 second using v1.01-cache-2.11-cpan-c333fce770f )