Thread Datum aus Kalenderwoche berechnen?? (6 answers)
Opened by Andreas at 2003-11-21 17:55

esskar
 2003-11-21 18:32
#72483 #72483
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use strict;

use Date::Calc qw(This_Year Week_of_Year);

my @month_max_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $this_year = This_Year();

sub is_leapyear
{
  my ($year) = @_;
  if(!$year)  { return "-1" }
  if($year % 4 == 0)   { $v = 1 }
  if($year % 100 == 0) { $v = 0 }
  if($year % 400 == 0) { $v = 1 }
  return $v;
}

my $is_leapyear = is_leapyear($this_year);
my %weeks_of_year = ();

for my $month (0 .. scalar(@month_max_days) - 1)
{
  my $week = 0;
  my @dates = ();  
  my $date = "";
  my $max_days = $month_max_days[$month];
  $max_days += 1 if $month == 1 and $is_leapyear;

  for my $day (0 .. $max_days-1)
  {
     ($week, undef) = Week_of_Year($this_year, $month, $day);
     unless(defines $weeks_of_year{$week})
     {
        $weeks_of_year{$week} = [];
     }
     $date = "$this_year.$month.$day";
     push @{$weeks_of_year{$week}}, $date;
  }  
}

print join(", ", @{$weeks_of_year{47}});


ungetestet... :)\n\n

<!--EDIT|esskar|1069435210-->

View full thread Datum aus Kalenderwoche berechnen??