#!/usr/bin/env perl

use 5.010;
use strict;
use warnings;

use Calendar::Indonesia::Holiday;
use DateTime;
use Perinci::CmdLine 1.06;

our $VERSION = '0.20'; # VERSION
our $DATE = '2014-06-26'; # DATE

our %SPEC;
$SPEC{list_id_workdays} = {
    v => 1.1,
    summary => '',
    args => {
        year       => {schema=>'int*'},
        month      => {schema=>['int*', between=>[1, 12]]},
        start_date => {schema=>'str*'},
        end_date   => {schema=>'str*'},
    },
};
sub list_id_workdays {
    my %args = @_;

    my %fargs;
    my $y = $args{year};
    my $m = $args{month};
    if ($y) {
        if ($m) {
            $fargs{start_date} = DateTime->new(year=>$y, month=>$m, day=>1);
            $m++; if ($m == 13) { $m=1; $y++ }
            $fargs{end_date} = DateTime->new(year=>$y, month=>$m, day=>1)
                ->subtract(days => 1);
        } else {
            $fargs{start_date} = DateTime->new(year=>$y, month=>1, day=>1);
            $fargs{end_date} = DateTime->new(year=>$y+1, month=>1, day=>1)
                ->subtract(days => 1);
        }
    }

    if ($args{start_date}) {
        $fargs{start_date} = $fargs{start_date};
    }
    if ($args{end_date}) {
        $fargs{end_date} = $fargs{end_date};
    }

    Calendar::Indonesia::Holiday::enum_id_workdays(%fargs);
}

Perinci::CmdLine->new(url => '/main/list_id_workdays')->run;

1;
# ABSTRACT: List Indonesian workdays
# PODNAME: list-id-workdays

__END__

=pod

=encoding UTF-8

=head1 NAME

list-id-workdays - List Indonesian workdays

=head1 VERSION

This document describes version 0.20 of list-id-workdays (from Perl distribution Calendar-Indonesia-Holiday), released on 2014-06-26.

=head1 SYNOPSIS

 $ list-id-workdays 2011

 # Show available options
 $ list-id-holidays --help

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Calendar-Indonesia-Holiday>.

=head1 SOURCE

Source repository is at L<https://github.com/sharyanto/perl-Calendar-Indonesia-Holiday>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Calendar-Indonesia-Holiday>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
