Calendar-Japanese-Holiday

 view release on metacpan or  search on metacpan

lib/Calendar/Japanese/Holiday.pm  view on Meta::CPAN


    return $holidays;
}

my $Cache_holidays_Year  = 0;
my $Cache_holidays_Month = 0;
my $Cache_holidays;

sub isHoliday {
    my ($year, $mon, $day, $furikae) = @_;

    $year = int($year);
    $mon = int($mon);
    $day = int($day);

    if ($mon < 1 || $mon > 12) {
	die('$mon argument is out of range.');
    }

    my $holidays;

    if ($year == $Cache_holidays_Year &&
	$mon  == $Cache_holidays_Month) {
	$holidays = $Cache_holidays;	# From Cache
    } else {
	$holidays = getHolidays($year, $mon, 1);
	return if not defined $holidays;
	# Cache
	$Cache_holidays = $holidays;
	$Cache_holidays_Year  = $year;
	$Cache_holidays_Month = $mon;
    }

    return if !exists $holidays->{$day};

    return if (!$furikae && $holidays->{$day} eq $FurikaeStr);

    return $holidays->{$day};
}

1;
__END__

=head1 NAME

Calendar::Japanese::Holiday - Japanese holidays in calender

=head1 SYNOPSIS

  use Calendar::Japanese::Holiday;

  # Getting a list of holidays
  $holidays = getHolidays(2008, 5);
  $holidays = getHolidays(2008, 5, 1);

  # Examining whether it is holiday or not.
  $name = isHoliday(2007, 5, 5);

=head1 DESCRIPTION

This module treats holidays information in Japanese calendar.
The list of holidays can be acquired, and you can examine whether
a day is holiday or not. You can acquire the holiday name too.

=head1 FUNCTIONS

=over 5

=item getHolidays($year, $month [, $furikae])

Returns a hash reference that has holidays in $year/$month.
Returns empty hash reference if no holidays.
It returns substitute holidays too if $furikae is true.
$furikae is false when $furikae is omitted.
$year is supported after 1948. A undef is returned if error ocucred.

 # Case 1 - $furikae is omitted
 $holidays = getHolidays(2008, 5);

 Return:
 $holidays = {
          '4' => "\x{307f}\x{3069}\x{308a}\x{306e}\x{65e5}",  # Midori-no-hi
          '3' => "\x{61b2}\x{6cd5}\x{8a18}\x{5ff5}\x{65e5}",  # Kenpou-Kinenbi
          '5' => "\x{3053}\x{3069}\x{3082}\x{306e}\x{65e5}"   # Kodomo-no-hi
        };

 # Case 2 - $furikae is true
 $holidays = getHolidays(2008, 5, 1);

 Return:
 $holidays = {
          '6' => "\x{632f}\x{66ff}",                          # Furikae
          '4' => "\x{307f}\x{3069}\x{308a}\x{306e}\x{65e5}",  # Midori-no-hi
          '3' => "\x{61b2}\x{6cd5}\x{8a18}\x{5ff5}\x{65e5}",  # Kenpou-Kinenbi
          '5' => "\x{3053}\x{3069}\x{3082}\x{306e}\x{65e5}"   # Kodomo-no-hi
        };

 # Case 3 - no holidays
 $holidays = getHolidays(2008, 6);

 Return:
 $holidays = {};

=item isHoliday($year, $month, $day [, $furikae])

Returns holiday name.
Returns undef if $year/$month/$day is not holiday.
$furikae is same as getHolidays().

 $name = isHoliday(2007, 5, 5);
 $name is "\x{3053}\x{3069}\x{3082}\x{306e}\x{65e5}" Kodomo-no-hi

=back

=head1 SEE ALSO

http://wiki.bit-hive.com/tomizoo/pg/Perl%20%BD%CB%C6%FC%CC%BE%A4%CE%BC%E8%C6%C0

(In Japanese document)

=head1 AUTHOR



( run in 1.435 second using v1.01-cache-2.11-cpan-b16cb0d3907 )