Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
185 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; |