sub tag_der_woche ($$$) {
# -----------------------------------------------------------------------------
# sub : t a g _ d e r _ w o c h e
# -----------------------------------------------------------------------------
# Autor : CD
# Aufgabe : Berechnet den Wochentag zu einem Datum.
#
# Vgl. http://www.informatik.uni-ulm.de/pm/mitarbeiter/mark/day_of_week.html
#
# Parameter : Tag (1-31), Monat (1-12) und Jahr (4-Stellig)
# Rückgabewert : 0 (Sonntag) bis 6 (Samstag)
# -----------------------------------------------------------------------------
# 0.0.1 - 17.01.2003 - CD - Erstellt
# 0.0.2 - 20.01.2003 - CD - Funktion ist_schaltjahr verwendet
# -----------------------------------------------------------------------------
my $t = shift;
my $m = shift;
my $j = shift;
print "tag_der_woche: t='$t', m='$m', j='$j'\n" if $Debug > 2;
# Abbruch der Funktion bei falshen Argumentübergaben:
return -1 unless defined($t) and defined($m) and defined($j);
return -2 unless 1 <= $t and $t <= 31;
return -3 unless 1 <= $m and $m <= 12;
return -4 unless 1592 <= $j and $j <= 2299;
my %jahrhundert = (15 => 0,
16 => 6,
17 => 4,
18 => 2,
19 => 0,
20 => 6,
21 => 4,
22 => 2,
);
my $jj = $j % 100; # letzte beiden Ziffern des Jahres
my $jh = int($j / 100); # Jahhundert (erste beide Ziffern des Jahres
my $schalt = ist_schaltjahr($j);
print "jh='$jh', jj='$jj', schalt='$schalt'\n" if $Debug > 2;
my $jhdtcode = $jahrhundert{$jh};
print "jhdtcode='$jhdtcode'\n" if $Debug > 2;
my $jahrcode = $jj + int($jj / 4);
print "jahrcode='$jahrcode'\n" if $Debug > 2;
my @monat = (1-$schalt, 4-$schalt, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6);
my $monatcode = $monat[$m-1];
print "monatcode='$monatcode'\n" if $Debug > 2;
my $tagcode = $jhdtcode + $jahrcode + $monatcode + $t;
--$tagcode; # damit Sonntag auf die 0 fällt...
$tagcode %= 7;
print "tagcode='$tagcode'\n" if $Debug > 2;
return $tagcode;
} # sub tag_der_woche
sub ist_schaltjahr ($) {
# -----------------------------------------------------------------------------
# sub : i s t _ s c h a l t j a h r
# -----------------------------------------------------------------------------
# Autor : CD
# Aufgabe : Gibt an, ob das übergebene Jahr ein Schaltjahr ist.
# Parameter : Jahr
# Rückgabewert : 0 oder 1
# -----------------------------------------------------------------------------
# 0.0.1 - 20.01.2003 - CD - Erstellt
# -----------------------------------------------------------------------------
my $j = shift;
return 1 if $j%4==0 and ($j%100!=0 or $j%400==0);
return 0;
} # sub ist_schaltjahr