#!perl
use warnings;
use strict;

# SPDX-FileContributor: Wesley Schwengle <waterkip@cpan.org>
#
# SPDX-License-Identifier: BSD

# ABSTRACT: Show vacation days for the day
# PODNAME: today-is

use Date::Holidays;
use DateTime;

binmode STDOUT, ":utf8";

my $today = DateTime->now();

my %default = (end_of_month => 'limit');
my $end;
if (@ARGV) {
    if ($ARGV[0] < 0) {
        $end = $today->clone;
        $today->add(days   => $ARGV[0], %default)
    }
    else {
        $end = $today->clone->add(days   => $ARGV[0], %default);
    }
}
else {
    $end = $today->clone->add(months => 1, %default);
}
my %dh;

my @countries = qw(aw nl bq cw);

foreach (@countries) {
  $dh{$_} = Date::Holidays->new(countrycode => $_);
}

$dh{waterkip} = Date::Holidays->new(countrycode => 'WATERKIP', nocheck => 1);
push(@countries, 'waterkip');

my $day = $today->clone;

my $rc;
while ($day <= $end) {
  $rc=undef;
  foreach (@countries) {
    $rc //= 1 if _is_holiday($dh{$_}, $day);
  }
  print "\n" if $rc;
  $day->add(days => 1);
}


sub _is_holiday {
  my $dh  = shift;
  my $day = shift;

  # This means a country isn't available
  return unless $dh;

  my $is = $dh->is_holiday_dt($day, gov => 1);
  return unless $is;
  printf("%s is %s in %s\n", $day->ymd, $is, $dh->{_countrycode});
  return 1;
}

# vim: ft=perl

__END__

=pod

=encoding UTF-8

=head1 NAME

today-is - Show vacation days for the day

=head1 VERSION

version 0.003

=head1 AUTHOR

Wesley Schwengle <waterkip@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2024 by Wesley Schwengle.

This is free software, licensed under:

  The (three-clause) BSD License

=cut
