Date::Holidays::* - coming to your country?

jonasbn on 2005-12-18T15:56:29

Locale::Country lists 240 countries. Out of these 240, 8 countries are present in the Date::Holidays::* namespace.

In order to make this namespace more usable, we need a better coverage - we need to go global :)

Currently the following countries are represented:

  • Norway, Denmark, Australia, New Zealand, Portugal, Germany, Great Britain/United Kingdom and France and USA is actually in preparation.

    But plenty of countries are not represented.

    I have just uploaded Date-Holidays_0.06 to CPAN, this module, contains documentation on how to comply with the other modules in the namespace.

    From Date::Holidays_0.06 (slightly modified):

    DEVELOPING A DATE::HOLIDAYS::* MODULE There is no control of the Date::Holidays::* namespace at all, so I am by no means an authority, but this is recommendations on order to make the modules in the Date::Holidays more uniform and thereby more usable.

    If you want to participate in the effort to make the Date::Holidays::* namespace even more usable, feel free to do so, your feedback and suggestions will be more than welcome.

    If you want to add your country to the Date::Holidays::* namespace, please feel free to do so. If a module for you country is already present, I am sure the author would not mind patches, suggestion or even help.

    If however you country does not seem to be represented in the namespace, you are more than welcome to become the author of the module in question.

    Please note that the country code is expected to be a two letter code based on ISO3166 (or Locale::Country).

    As an experiment I have added two modules to the namespace, Date::Holidays::Abstract and Date::Holidays::Super, abstract is attempt to make sure that the module implements the expected methods.

    So by using abstract your module will not work until it follows the the abstract layed out for a Date::Holidays::* module. Unfortunately the module will only check for the presence of the methods not their prototypes.

    Date::Holidays::Super is for the lazy programmer, it implements the necessary methods as stubs and there for do not have to implement anything, but your module will not return anything of value. So the methods need to be overwritten in order to comply with the expected output of a Date::Holidays::* method.

    The methods which are currently interesting in a Date::Holidays::* module are:

    is_holiday Takes 3 arguments: year, month, day and returns the name of the holiday as a scalar in the national language of the module context in question. Returns undef if the requested day is not a holiday.

    Modified example taken from: Date::Holidays::DK use Date::Holidays::DK; my ($year, $month, $day) = (localtime)[ 5, 4, 3 ]; $year += 1900; $month += 1; print "Woohoo" if is_holiday( $year, $month, $day );

    #The actual method might not be implemented at this time in the #example module.

    is__holiday Same as above.

    This method however should be a wrapper of the above method (or the other way around).

    holidays Takes 1 argument: year and returns a hashref containing all of the holidays in specied for the country, in the national language of the module context in question.

    The keys are the dates, month + day in two digits each contatenated.

    Modified example taken from: Date::Holidays::PT

    my $h = holidays($year); printf "Jan. 1st is named '%s'\n", $h->{'0101'};

    #The actual method might not be implemented at this time in the #example module. _holidays This method however should be a wrapper of the above method (or the other way around).

    Only is_holiday and holidays are implemented in Date::Holidays::Super and are required by Date::Holidays::Abstract.

    ADDITIONAL PARAMETERS Some countries are divided into regions or similar and might require additional parameters in order to give more exact holiday data.

    This is handled by adding additional parameters to is_holiday and holidays.

    These parameters are left to the module authors descretion and the actual Date::Holidays::* module should be consulted.

    Example Date::Holidays::AU use Date::Holidays::AU qw( is_holiday ); my ($year, $month, $day) = (localtime)[ 5, 4, 3 ]; $year += 1900; $month += 1; my ($state) = 'VIC'; print "Excellent\n" if is_holiday( $year, $month, $day, $state );