Skip to content

Commit

Permalink
Import von Version 0.6
Browse files Browse the repository at this point in the history
git-svn-id: file:///opt/svn/scripts/misc/perl/cpan/Date-Holidays-DE/trunk@72 484cc3a2-7d94-4784-8140-313c9a92d1de
  • Loading branch information
martin committed May 19, 2008
1 parent 3d9f37a commit 13a343c
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 24 deletions.
7 changes: 6 additions & 1 deletion Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension Date::German::Holiday. Revision history for Perl extension Date::Holidays::DE


v.0.5 Fri Nov 21 18:08:21 CET 2003 v.0.5 Fri Nov 21 18:08:21 CET 2003
- Initial public release - Initial public release


v.0.6 Sun Nov 23 12:37:56 CET 2003
- Option to include the internal Alias in the generated list
- Option to generate a list of all known holidays
- Added example scripts

84 changes: 61 additions & 23 deletions DE.pm
@@ -1,5 +1,4 @@
package Date::Holidays::DE; package Date::Holidays::DE;
# $Id$


use strict; use strict;
use warnings; use warnings;
Expand All @@ -15,7 +14,7 @@ require Exporter;


our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT_OK = qw(holidays); our @EXPORT_OK = qw(holidays);
our $VERSION = '0.5'; our $VERSION = '0.6';


sub holidays{ sub holidays{
my %parameters = ( my %parameters = (
Expand Down Expand Up @@ -44,7 +43,7 @@ sub holidays{
# fron = Fronleichnam # fron = Fronleichnam
# 1mai = Maifeiertag # 1mai = Maifeiertag
# mari = Mariae Himmelfahrt # mari = Mariae Himmelfahrt
# 3oct = Tag der deutschen Einheit # 3okt = Tag der deutschen Einheit
# refo = Reformationstag # refo = Reformationstag
# alhe = Allerheiligen # alhe = Allerheiligen
# buss = Buss- und Bettag # buss = Buss- und Bettag
Expand Down Expand Up @@ -230,10 +229,22 @@ sub holidays{
# Build list for returning # Build list for returning
# #
my %holidaylist; my %holidaylist;
# Walk the scope information passed via the WHERE parameter # See what holidays shall be printed
foreach my $scope (@{$parameters{'WHERE'}}){ my $wantall = 0;
foreach my $alias(@{$holidays{$scope}}){ foreach (@{$parameters{'WHERE'}}){
$holidaylist{$alias} = $holiday{$alias}; if ($_ eq 'all'){
$wantall = 1;
}
}
if (1 == $wantall){
# All holidays if 'all' is in the WHERE parameter list.
%holidaylist = %holiday;
}else{
# Only specified regions
foreach my $scope (@{$parameters{'WHERE'}}){
foreach my $alias(@{$holidays{$scope}}){
$holidaylist{$alias} = $holiday{$alias};
}
} }
} }
# Add the most obscure holidays that were requested through # Add the most obscure holidays that were requested through
Expand Down Expand Up @@ -263,18 +274,20 @@ sub holidays{
# Sort values stored in the hash for returning # Sort values stored in the hash for returning
# #
my @returnlist; my @returnlist;
foreach(sort{$a <=> $b} (values(%holidaylist))){ foreach(sort{$holidaylist{$a}<=>$holidaylist{$b}}(keys(%holidaylist))){
# See if this platform has strftime(%s) # See if this platform has strftime(%s)
# if not, inject seconds manually into format string. # if not, inject seconds manually into format string.
my $formatstring = $parameters{'FORMAT'}; my $formatstring = $parameters{'FORMAT'};
if (strftime('%s', localtime($_)) eq '%s'){ if (strftime('%s', localtime($holidaylist{$_})) eq '%s'){
$formatstring =~ s/%s/$_/g; $formatstring =~ s/%{0}%s/$holidaylist{$_}/g;
} }
push @returnlist, # Inject the holiday's alias name into the format string
strftime($formatstring, localtime($_)); # if it was requested by adding %#.
$formatstring =~ s/%{0}%#/$_/;
push @returnlist,
strftime($formatstring, localtime($holidaylist{$_}));
} }
return \@returnlist; return \@returnlist;

} }


sub _date2timestamp{ sub _date2timestamp{
Expand All @@ -289,7 +302,7 @@ __END__
=head1 NAME =head1 NAME
Date::Holidays::DE - Determine German holidays in Perl Date::Holidays::DE - Determine German holidays
=head1 SYNOPSIS =head1 SYNOPSIS
Expand All @@ -302,7 +315,7 @@ Date::Holidays::DE - Determine German holidays in Perl
This module exports a single function named B<holidays()> which returns a list of This module exports a single function named B<holidays()> which returns a list of
German holidays in a given year. German holidays in a given year.
=head2 KNOWN HOLIDAYS =head1 KNOWN HOLIDAYS
The module knows about the following holidays: The module knows about the following holidays:
Expand All @@ -319,7 +332,7 @@ The module knows about the following holidays:
fron Fronleichnam Corpus christi fron Fronleichnam Corpus christi
1mai Maifeiertag Labor day, German style 1mai Maifeiertag Labor day, German style
mari Mariae Himmelfahrt Assumption day mari Mariae Himmelfahrt Assumption day
3oct Tag der deutschen Einheit Reunion day 3okt Tag der deutschen Einheit Reunion day
refo Reformationstag Reformation day refo Reformationstag Reformation day
alhe Allerheiligen All hallows day alhe Allerheiligen All hallows day
buss Buss- und Bettag Penance day buss Buss- und Bettag Penance day
Expand All @@ -333,7 +346,9 @@ holiday is calculated. Too much detail would be far beyond the scope of this
document, but it's not particularly hard once you've found the date for document, but it's not particularly hard once you've found the date for
Easter. Easter.
=head1 OUTPUT FORMAT =head1 USAGE
=head2 OUTPUT FORMAT
The list returned by B<holidays()> consists of UNIX-Style timestamps in seconds The list returned by B<holidays()> consists of UNIX-Style timestamps in seconds
since The Epoch. You may pass a B<strftime()> style format string to get the since The Epoch. You may pass a B<strftime()> style format string to get the
Expand All @@ -351,9 +366,20 @@ examples to get you started:
Please consult the manual page of B<strftime()> for a complete list of available Please consult the manual page of B<strftime()> for a complete list of available
format definitions. format definitions.
There is, however, one "proprietary" extension to the formats of B<strftime()>:
The format definition I<%#> will print the internal abbreviation used for each
holiday.
FORMAT=>"%#:%d.%m" wei1:25.12.
As the module doesn't want to deal with i18n
issues, you'll have to find your own way to translate the aliases into your
local language. See the I<example/feiertage.pl> script included in the
distribution to get the idea. This was added in version 0.6.
=head2 LOCAL HOLIDAYS =head2 LOCAL HOLIDAYS
The modules also knows about different regulations throughout Germany. The module also knows about different regulations throughout Germany.
When calling B<holidays()>, the resulting list by default contains the list of When calling B<holidays()>, the resulting list by default contains the list of
Germany-wide holidays. Germany-wide holidays.
Expand Down Expand Up @@ -392,6 +418,12 @@ German holidays, use the following:
returns the list of common German holidays merged with the list of holidays returns the list of common German holidays merged with the list of holidays
specific to Baden-Wuerttemberg. specific to Baden-Wuerttemberg.
You can also request a list containing all holidays this module knows about:
my $feiertage_ref = holidays(WHERE=>['all']);
will return a list of all known holidays. This was added in version 0.6.
=head2 ADDITIONAL HOLIDAYS =head2 ADDITIONAL HOLIDAYS
There are a number of holidays that aren't really holidays, e.g. New Year's Eve There are a number of holidays that aren't really holidays, e.g. New Year's Eve
Expand Down Expand Up @@ -425,11 +457,10 @@ To disable this behaviour, set the I<WEEKENDS> option to 0:
my $feiertage_ref = holidays(WEEKENDS=>0); my $feiertage_ref = holidays(WEEKENDS=>0);
=head1 COMPLETE EXAMPLE =head1 COMPLETE EXAMPLE
Get all holidays for Germany and Bayern in 2004, count New Year's Eve and Get all holidays for Germany and Bayern in 2004, count New Year's Eve and
Christmas Eve as Holidays. Also, we live in a catolic region where Assumption Christmas Eve as Holidays. Also, we live in a catholic region where Assumption
day is a holiday, too. Exclude weekends and return the date list in human day is a holiday, too. Exclude weekends and return the date list in human
readable format: readable format:
Expand All @@ -452,7 +483,7 @@ please drop the author a note.
=head1 OFFICIAL HOLIDAY DATES =head1 OFFICIAL HOLIDAY DATES
The official holiday dates are published by the Federal Ministry of the The official holiday dates are published by the German Federal Ministry of the
Interior at: Interior at:
http://www.bmi.bund.de/services/lexikon/lexikon.jsp?key=F&hit=Feiertage http://www.bmi.bund.de/services/lexikon/lexikon.jsp?key=F&hit=Feiertage
Expand All @@ -466,8 +497,15 @@ flexible formatting. This limits the range of years to work on to
the years from 1972 to 2037. the years from 1972 to 2037.
B<Date::Holidays::DE> doesn't know anything about past holiday regulations. B<Date::Holidays::DE> doesn't know anything about past holiday regulations.
I<Tag der Deutschen Einheit>, for example, was changed from June 17th to I<Tag der Deutschen Einheit>, for example, was moved in 1991 from June 17th
October 3rd after the reunion of the eastern and western parts of Germany. to October 3rd after the reunion of the eastern and western parts of Germany.
None of the calendar programs the author has looked at, know about June 17th.
B<Date::Holidays::DE> is not configurable. Holiday changes don't come over
night and a new module release can be rolled out within a single day.
B<Date::Holidays::DE> probably won't work in Microsoft's "Windows" operating
environment.
=head1 AUTHOR =head1 AUTHOR
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST
Expand Up @@ -4,3 +4,5 @@ MANIFEST
Makefile.PL Makefile.PL
README README
test.pl test.pl
example/feiertage.pl
example/werktage-diff.pl
55 changes: 55 additions & 0 deletions example/feiertage.pl
@@ -0,0 +1,55 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Holidays::DE qw(holidays);

# Sample script for Date::Holidays::DE by Martin Schmitt <mas at scsy dot de>

# Assign full names to the internal aliases from Date::Holidays::DE
# See the manpage for a list of all aliases.
my %feiertagsnamen = (
'neuj' => 'Neujahrstag',
'hl3k' => 'Hl. 3 Könige',
'romo' => 'Rosenmontag',
'fadi' => 'Faschingsdienstag',
'karf' => 'Karfreitag',
'osts' => 'Ostersonntag',
'ostm' => 'Ostermontag',
'pfis' => 'Pfingstsonntag',
'pfim' => 'Pfingstmontag',
'himm' => 'Himmelfahrtstag',
'fron' => 'Fronleichnam',
'1mai' => 'Maifeiertag',
'mari' => 'Mariä Himmelfahrt',
'3okt' => 'Tag der deutschen Einheit',
'refo' => 'Reformationstag',
'alhe' => 'Allerheiligen',
'buss' => 'Buß- und Bettag',
'heil' => 'Heiligabend',
'wei1' => '1. Weihnachtstag',
'wei2' => '2. Weihnachtstag',
'silv' => 'Silvester'
);
# This year is $dieses
my $dieses = (localtime(time()))[5] + 1900;

# Next year is $naechstes
my $naechstes = $dieses + 1;

# Get the list of holidays for next year
my @feiertage = @{holidays( WHERE => ['all'],
FORMAT => "%#:%d.%m.%Y",
YEAR => $naechstes
)};

print "Feiertage für $naechstes:\n";
print "-------------------\n";

foreach (@feiertage){
# Split name and date
my ($name, $datum) = split /:/;
# Print name from $feiertagsnamen along with the date
printf ("%-30s: %10s\n", $feiertagsnamen{$name}, $datum);
}

exit 0;
61 changes: 61 additions & 0 deletions example/werktage-diff.pl
@@ -0,0 +1,61 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Holidays::DE qw(holidays);
use Date::Business;

# Sample script for integration of Date::Holidays::DE with Date::Business

# Script by Martin Schmitt <mas at scsy dot de>

# Calculate the difference between two dates using three different
# methods from Date::Business

my $startdate = "20030414"; # Monday before Easter 2003
my $enddate = "20030428"; # Monday after Easter monday 2003
my $year = "2003"; # Not particularly elaborate, but okay for now

print "Abstand zwischen $startdate und $enddate...\n";

# 1. Not excluding weekends and holidays (Should be 14 days difference)
#
# Initialize start and ending dates
my $start1 = new Date::Business(DATE => $startdate);
my $end1 = new Date::Business(DATE => $enddate);
my $diff1 = $end1->diff($start1);
print "$diff1 Tage (Wochenenden und Feiertage unberücksichtigt)\n";

# 2. Excluding weekends (Should be 10 days difference)
#
# Initialize start and ending dates
my $start2 = new Date::Business(DATE => $startdate);
my $end2 = new Date::Business(DATE => $enddate);
my $diff2 = $end2->diffb($start2);
print "$diff2 Tage (Wochenenden berücksichtigt, Feiertage unberücksichtigt)\n";

# 3. Excluding weekends and holidays (Should be 8 days difference)
#
# Prepare a subroutine for use by Date::Business
sub business_holiday{
my ($start, $end) = @_;
my $count;
# Get the holiday list from Date::Holidays::DE
my @holidays = @{holidays(YEAR=>$year,
FORMAT => "%Y%m%d", # This is important here
WEEKENDS => 0)};
foreach (@holidays){
# Count holidays between the start and end dates
$count++ if (($start <= $_) and ($_ <= $end));
}
return $count;
}

# Initialize start and ending dates including reference to the above subroutine
my $start3 = new Date::Business(DATE => $startdate,
HOLIDAY => \&business_holiday);
my $end3 = new Date::Business(DATE => $enddate,
HOLIDAY => \&business_holiday);
my $diff3 = $end3->diffb($start3);
print "$diff3 Tage (Wochenenden und Feiertage berücksichtigt)\n";

exit 0;

0 comments on commit 13a343c

Please sign in to comment.