mit POSIX
package KW;
use POSIX;
use strict;
use warnings;
# Wochentag numerisch {num},
# abgekürzt{abb}, voll{full}
sub wd{
my $self = shift;
my $day = shift;
my $month = shift;
my $year = shift;
my %hunt = split /\s+/, strftime(
'num %w abb %a full %A', 0, 0, 0,
$day, $month-1, $year-1900
);
return \%hunt;
}
# Wieviele Wochen hat ein Jahr
sub weeks_in_year{
my $self = shift;
my $year = shift;
return
$self->wd(1,1,$year)->{num} == 4 || $self->wd(31,12,$year)->{num} == 4 ?
53 : 52;
}
# Datum für Montag in erster KW eines Jahres
sub first{
my $self = shift;
my $year = shift;
my %cwd = (
0 => sprintf("02.01.%d", $year),
1 => sprintf("01.01.%d", $year),
2 => sprintf("31.12.%d", $year-1),
3 => sprintf("30.12.%d", $year-1),
4 => sprintf("29.12.%d", $year-1),
5 => sprintf("04.01.%d", $year),
6 => sprintf("03.01.%d", $year)
);
$cwd{$self->wd(1,1,$year)->{num}};
}
1;
print KW->first(2027);
Viel Spaß damit