Date-Holidays-KZ

 view release on metacpan or  search on metacpan

lib/Date/Holidays/KZ.pm  view on Meta::CPAN


=head2 $Date::Holidays::KZ::strict

Allows you to return an error if the requested date is outside the determined times.
Default is 0.

=cut

our $strict = 0;

use Carp;
use Time::Piece;
use List::Util qw/ first /;

# internal date formatting alike ISO 8601: MMDD
my @REGULAR_HOLIDAYS = (
    {
        name => 'Новый год',
                days => [ qw( 0101 0102 ) ],
    },
    {
        name => 'Православное рождество',
        days => '0107',
    },
    {
        name => 'Международный женский день',
        days => '0308',
    },
    {
        name => 'Наурыз мейрамы',
        days => [ qw( 0321 0322 0323 ) ],
    },
    {
        name => 'Праздник единства народа Казахстана',
        days => '0501',
    },
    {
        name => 'День защитника Отечества',
        days => '0507',
    },
    {
        name => 'День Победы',
        days => '0509',
    },
    {
        name => 'День Столицы',
        days => '0706',
    },
    {
        name => 'День Конституции Республики Казахстан',
        days => '0830',
    },
    {
        name => 'День Первого Президента Республики Казахстан',
        days => '1201',
    },
    {
        name => 'День Независимости',
        days => [ qw( 1216 1217 ) ],
    },
    # Курбан-айта goes to HOLIDAYS_SPECIAL because based on the muslim calendar
);

my %HOLIDAYS_SPECIAL = (
    2016 => [ qw( 0104 0307 0502 0510 0912 1219 ) ],
    2017 => [ qw( 0103 0320 0508 0707 0901 1218 1219 ) ],
    2018 => [ qw( 0821 0309 0508 0430 0831 1203 1218 1231 ) ],
    2019 => [ qw( 0325 0510 0708 1202 0811 ) ],
    2020 => [ qw( 0103 0309 0324 0325 0508 0831 1218 ) ],
    2021 => [ qw( 0104 0324 0503 0510 0705 0720 0910 ) ],
    2022 => [ qw( 0103 0104 0502 0510 0307 0829 1219 ) ],
);


my %BUSINESS_DAYS_ON_WEEKENDS = (
    2016 => [ qw( 0305 ) ],
    2017 => [ qw( 0318 0701 ) ],
    2018 => [ qw( 0303 0505 0825 1229 ) ],
    2019 => [ qw( 0504 ) ],
    2020 => [ qw( 0105 1220 ) ],
    2021 => [ qw( 0703 ) ],
    2022 => [ qw( 0305 0827 ) ],
);

my %SHORT_BUSINESS_DAYS = (
);

=head2 is_holiday( $year, $month, $day )

Determine whether this date is a KZ holiday. Returns holiday name or undef.

=cut

sub is_holiday {
    my ( $year, $month, $day ) = @_;
    croak 'Bad params'  unless $year && $month && $day;

    return holidays( $year )->{ _get_date_key($month, $day) };
}

=head2 is_kz_holiday( $year, $month, $day )

Alias for is_holiday().

=cut

sub is_kz_holiday {
    goto &is_holiday;
}

=head2 holidays( $year )

Returns hash ref of all KZ holidays in the year.

=cut

my %cache;
sub holidays {
    my $year = shift or croak 'Bad year';

    return $cache{ $year }  if $cache{ $year };



( run in 1.014 second using v1.01-cache-2.11-cpan-8dfa8b56332 )