Location: PHPKode > projects > lcdata > lcdata-0.0.1/frontend-web/includes/datefunct.php
<?

function isleapyear($myyear){
  $leapyear=0;
  if (($myyear % 4)==0){
    $leapyear=1;
  }
  if ((($myyear % 100)==0) && (($myyear % 400)==1)){
    $leapyear=0;
  }
  return $leeapyear;
}


// Gibt Tag zurueck wieviel Tage nach dem 21.3 Ostern in diesem Jahr ist.
//
function old_easter_days($myyear){
  $easter_days=0;
  if ($myyear==1995){
    $easter_days=26;
  }
  if ($myyear==1996){
    $easter_days=17;
  }
  if ($myyear==1997){
    $easter_days=9;
  }
  if ($myyear==1998){
    $easter_days=22;
  }
  if ($myyear==1999){
    $easter_days=14;
  }
  if ($myyear==2000){
    $easter_days=33;
  }
  if ($myyear==2001){
    $easter_days=25;
  }
  if ($myyear==2002){
    $easter_days=41;
  }
  if ($myyear==2003){
    $easter_days=30;
  }
  if ($myyear==2004){
    $easter_days=21;
  }
  if ($myyear==2005){
    $easter_days=37;
  }
  return($easter_days);
}


// Gibt Feiertag fuer ein Datum zurueck
//
function holiday($myday,$mymonth,$myyear){
  $holyday="";

  list ($long,$weekday) = date2long ($myday,$mymonth,$myyear);  

  if (($myday==1)&&($mymonth==1)){
    $holyday="Neujahr";
  } 
  if (($myday==1)&&($mymonth==5)){
    $holyday="1.Mai";
  }
  if (($myday==3)&&($mymonth==10)){
    $holyday="D.Einheit";
  }

  if (($myday==1)&&($mymonth==11)){
    $holyday="Allerheiligen";
  }
  if (($myday==25)&&($mymonth==12)){
    $holyday="1.Weihnacht";
  }
  if (($myday==26)&&($mymonth==12)){
    $holyday="2.Weihnacht";
  } 


  if (($myday==24)&&($mymonth==12)){
    $holyday="Heiligabend";
  } 
  if (($myday==31)&&($mymonth==12)){
    $holyday="Sylvester";
  }

  list($today,$weekday) = date2long ($myday,$mymonth,$myyear);
  list($equinox,$weekday) = date2long (21,3,$myyear);
  $easter= $equinox+ easter_days($myyear);

  if ($today==$easter-48){
    $holyday="Rosenmontag";
  }
  if ($today==$easter-47){
    $holyday="Karnevalsdienstag";
  }
  if ($today==$easter-46){
    $holyday="Aschermittwoch";
  }
  if ($today==$easter-7){
    $holyday="Palmsonntag";
  }
  if ($today==$easter-2){
    $holyday="Karfreitag";
  }
  if ($today==$easter-1){
    $holyday="Osternsamstag";
  }
  if ($today==$easter){
    $holyday="Ostern";
  }
  if ($today==$easter+1){
    $holyday="Ostermontag";
  }
  if ($today==$easter+39){
    $holyday="Himmelfahrt";
  }
  if ($today==$easter+49){
    $holyday="Pfingstsonntag";
  }
  if ($today==$easter+50){
    $holyday="Pfingstmontag";
  }
  if ($today==$easter+60){
    $holyday="Fronleichnam";
  }

  list ($firstmai,$weekday)=date2long (1,5,$myyear);
  $muttertag=$firstmai+13-$weekday;
  if ($today==$muttertag){
    $holyday="Muttertag";
  }

  return($holyday);
}


// Berechnet Tag, Monat, Jahr aus Long(Tage am dem 1.1.1600)
// 
function long2date($mydays){

        $startdays=$mydays;
	$myyear=floor($mydays/365);

	$mydays=$mydays -($myyear*365);
	$mydays=$mydays - floor(($myyear-1)/4);
	$mydays=$mydays + floor(($myyear-1)/100);
	$mydays=$mydays - floor(($myyear-1)/400);

        if ($mydays<=0) {
           $myyear=$myyear-1;
           $mydays=$startdays;

           $mydays=$mydays - ($myyear* 365);
	   $mydays=$mydays - floor(($myyear-1)/4);
	   $mydays=$mydays + floor(($myyear-1)/100);
  	   $mydays=$mydays - floor(($myyear-1)/400);
        }


	if ($myyear>0){
//	  $mydays=$mydays-1;
	}

	$leapyear=0;
	  if (($myyear % 4)==0){
	    $leapyear=1;
	  }
	  if ((($myyear % 100)==0) && (($myyear % 400)==1)){
	    $leapyear=0;
	  }

	$myyear=$myyear+1600;


        $yeardays=$mydays;

	$jan=0;
	$feb=31;
	$mar=$feb+28+$leapyear;
	$apr=$mar+31;
	$may=$apr+30;
	$jun=$may+31;
	$jul=$jun+30;
	$aug=$jul+31;
	$sep=$aug+31;
	$oct=$sep+30;
	$nov=$oct+31;
	$dec=$nov+30;
	$mymonth=1;		// Januar
	if ($mydays>$dec){
	   $mymonth=12;
	   $mydays=$mydays-$dec;
	}
	if ($mydays>$nov){
	   $mymonth=11;
	   $mydays=$mydays-$nov;
	}
	if ($mydays>$oct){
	   $mymonth=10;
	   $mydays=$mydays-$oct;
	}
	if ($mydays>$sep){
	   $mymonth=9;
	   $mydays=$mydays-$sep;
	}
	if ($mydays>$aug){
	   $mymonth=8;
	   $mydays=$mydays-$aug;
	}
	if ($mydays>$jul){
	   $mymonth=7;
	   $mydays=$mydays-$jul;
	}
	if ($mydays>$jun){
	   $mymonth=6;
	   $mydays=$mydays-$jun;
	}
	if ($mydays>$may){
	   $mymonth=5;	
	   $mydays=$mydays-$may;
	}
	if ($mydays>$apr){	
	   $mymonth=4;
	   $mydays=$mydays-$apr;
	}
	if ($mydays>$mar){
	   $mymonth=3;
	   $mydays=$mydays-$mar;
	}
	if ($mydays>$feb){
	   $mymonth=2;
	   $mydays=$mydays-$feb;
	}

	$myday=$mydays;

        // Berechne Kalender-Woche 

        $mykw=1;
 
        // liegen

	list ($days,$weekday) = date2long(1,1,$myyear);  
        $yeardays=$yeardays-7+$weekday;
        if ($weekday<4){
          $mykw=2;
        }

        $mykw=$mykw+floor(($yeardays)/7);
        if ($mykw>52){
	  list ($days,$weekday) = date2long(1,1,$myyear+1);
          if (($weekday>0)&&($weekday<4)){
            $mykw=1;
          }           
        }

        if ($mykw==0){
          $mykw=53; 
        }
 return array($myday,$mymonth,$myyear,$mykw);
}


//  Function date2long (long day, long month, long year)
//  returns  long   = tag nr seit dem 1.1.1600
//                    
function date2long($cday,$cmonth,$cyear){
        global $lb_monday,$lb_tuesday,$lb_wednesday,$lb_thursday,$lb_friday,$lb_saturday,$lb_sunday;

	$sday=1;		// calender START day
	$smonth=1;
	$syear=1600;

	$days=($cyear-$syear)*365;
	$days=$days + floor(($cyear-$syear)/4);
	$days=$days - floor(($cyear-$syear)/100);
	$days=$days + floor(($cyear-$syear)/400);


	$leapyear=0;
	if (($cyear % 4)==0){
	  $leapyear=1;
	}
	if (($cyear % 100)==0){
	  $leapyear=0;
	}
	if (($cyear % 400)==0){
	  $leapyear=1;
	}

	$jan=0;
	$feb=31;
	$mar=$feb+28+$leapyear;
	$apr=$mar+31;
	$may=$apr+30;
	$jun=$may+31;
	$jul=$jun+30;
	$aug=$jul+31;
	$sep=$aug+31;
	$oct=$sep+30;
	$nov=$oct+31;
	$dec=$nov+30;

	
	switch ($cmonth) {
	  case 1:
	    $days=$days+$jan;
	    break;
	  case 2:
	    $days=$days+$feb;
	    break;
	  case 3:
	    $days=$days+$mar;
	    break;
	  case 4:
	    $days=$days+$apr;
	    break;
	  case 5:
	    $days=$days+$may;
	    break;
	  case 6:
	    $days=$days+$jun;
	    break;
	  case 7:
	    $days=$days+$jul;
	    break;
	  case 8:
	    $days=$days+$aug;
	    break;
	  case 9:
	    $days=$days+$sep;
	    break;
	  case 10:
	    $days=$days+$oct;
	    break;
	  case 11:
	    $days=$days+$nov;	
	    break;
	  case 12:
	    $days=$days+$dec;
	    break;
	}

	$days=$days+$cday-$sday;
	$weekday=((5+$days) % 7);			// der 1.1. 1600 war ein Dienstag

  return array($days,$weekday);				// Tagnr seit 1.1.1600 und wochentagnr (0=montag,6=sonntag)
}

function getstrweekday($weekday){
        global $lb_monday,$lb_tuesday,$lb_wednesday,$lb_thursday,$lb_friday,$lb_saturday,$lb_sunday;
$sweekday="gunnar";
	switch ($weekday) {
	  case 0:
	    $sweekday="$lb_monday";
	    break;
	  case 1:
	    $sweekday="$lb_tuesday";
	    break;
	  case 2:
	    $sweekday="$lb_wednesday";
	    break;	
	  case 3:
	    $sweekday="$lb_thursday";
	    break;
	  case 4:	
	    $sweekday="$lb_friday";
	    break;
	  case 5:
	    $sweekday="<font color=\"#884400\">$lb_saturday</font>";
	    break;
	  case 6:
	    $sweekday="<font color=\"#660000\">$lb_sunday</font>";
	    break;
	}
  return($sweekday); 
}


?>
Return current item: lcdata