Zend - The PHP Company




Calendars

Add Code


Jewish calendar class  

Type: application
Added by: yehosef
Entered: 04/04/2002
Last modified: 01/11/2008
Rating: - (fewer than 3 votes)
Views: 5109
Class for creating simple Jewish Calendars based on code by senjin (http://www.zend.com/codex.php?id=213&single=1)


<?

/* Modified by Yehosef Shapiro, 8th day of the Omer, 5762 */

/* determine whether the year passed is a leap year.
I do not know if this is correct.  I knew that every 19 years
the calendar is the same and I used the program from www.kaluach.org
to find which years are leap year  */
function isleapyear($year)
{
  
$remander=$year%19;
  switch(
$remander)
  {
    case 
0:
    case 
3:
    case 
6:
    case 
8:
    case 
11:
    case 
14:
    case 
17:
      return 
true;
      break;
    default:
      return 
false;
      break;
  }
}

/* return the month name.  Month 7 is not Nisan but Adar II even
in non-leap years. */
function monthname($monthint$yearint)
{
  switch (
$monthint) {
    case 
1:
        
$english="Tishrei";
        break;
    case 
2:
        
$english="Heshvan";
        break;
    case 
3:
        
$english="Kislev";
        break;
    case 
4:
        
$english="Tevet";
        break;
    case 
5:
        
$english="Shevat";
        break;
    case 
6:
        if (
isleapyear($yearint))
          
$english="Adar I";
        else
          
$english="Adar";
        break;
    case 
7:
        
$english="Adar II";
        break;
    case 
8:
        
$english="Nisan";
        break;
    case 
9:
        
$english="Iyyar";
        break;
    case 
10:
        
$english="Sivan";
        break;
    case 
11:
        
$english="Tammuz";
        break;
    case 
12:
        
$english="Av";
        break;
    case 
13:
        
$english="Elul";
        break;
    default:
        break;
  }
  return 
$english;
}

/* This is a function to determine the number of days
// in a given Hebrew month.  The months are counted
// from Tishrei and the year is the Hebrew year  */
function numdays($monthint,$yearint)
{
    
// retreive a julian day count for the middle of the requested month
    
$JD=jewishtojd($monthint,15,$yearint);

    
// create Jewish calendar for this month (maybe unnecessary)
    
$cal=jdtojewish($JD);

    
// create a jewish calendar for the next month
    
$calnext=jdtojewish($JD+28);
    
    
// break apart the date string for the next month - we want the days
    
$calnextary=explode("/",$calnext);

    
//the return line is doing the following:

    //$daysleft=28-$calnextary[1];
    //return 15+$daysleft;

    /* we want the date that the requested month becomes the next month
    // So we take the 15th and add 28 days (about a month).  Then we'll
    // check the number of days into the next month 28 +15 is and that gives
    // the days of the current month.  */
    
return 15+28-$calnextary[1];
}



class 
calendar {
    var
       
$daynamefont,$daynamebgcolor,$daynamecolor,$daynamesize,$daynamebold,$daynameitalic,
       
$dayfont,$daybgcolor,$daycolor,$dayactivecolor,$daysize,$daybold,$dayitalic,
       
$showdate,$bordersize,$timestamp,$day,$month,$year;

  function 
calendar()
  {
      if(empty(
$this->daynamefont)==true)$this->daynamefont="Arial, sans-serif";
      if(empty(
$this->daynamebgcolor)==true)$this->daynamebgcolor="#000060";
      if(empty(
$this->daynamecolor)==true)$this->daynamecolor="#FFFFFF";
      if(empty(
$this->daynamesize)==true)$this->daynamesize="1";
      if(empty(
$this->daynamebold)==true)$this->daynamebold=true;
      if(empty(
$this->daynameitalic)==true)$this->daynameitalic=false;
      if(empty(
$this->dayfont)==true)$this->dayfont="Arial, sans-serif";
      if(empty(
$this->daybgcolor)==true)$this->daybgcolor="#FFCA00";
      if(empty(
$this->daycolor)==true)$this->daycolor="#000000";
      if(empty(
$this->dayactivecolor)==true)$this->dayactivecolor="#FF0000";
      if(empty(
$this->daysize)==true)$this->daysize="1";
      if(empty(
$this->daybold)==true)$this->daybold=true;
      if(empty(
$this->dayitalic)==true)$this->dayitalic=false;
      if(empty(
$this->showdate)==true)$this->showdate=true;
      if(empty(
$this->showyear)==true)$this->showyear=true;
      if(empty(
$this->bordersize)==true)$this->bordersize="2";

      
$today=explode("/",jdtojewish(unixtojd()));
      if(empty(
$this->day)==true)$this->day=$today[1];
      if(empty(
$this->month)==true)$this->month=$today[0];
      if(empty(
$this->year)==true)$this->year=$today[2];
      
  }

  function 
show()
  {
     if(
$this->daynamebold==true){
        
$daynametextprefix="<b>";
        
$daynametextsuffix="</b>";
      }
      if(
$this->daynameitalic==true){
        
$daynametextprefix.="<i>";
        
$daynametextsuffix="</i>".$daynametextsuffix;
      }
      if(
$this->daybold==true){
        
$daytextprefix="<b>";
        
$daytextsuffix="</b>";
      }
      if(
$this->dayitalic==true){
        
$daytextprefix.="<i>";
        
$daytextsuffix="</i>".$daytextsuffix;
      }

        
$maxdays=numdays($this->month,$this->year);
        
$startday=1-jddayofweek(jewishtojd($this->month,1,$this->year),0);
        print(
"<table border='".$this->bordersize."' cellspacing='0' cellpadding='0'><tr bgcolor='".$this->daybgcolor."'><td>n");
        print(
"  <table border='0' cellspacing='0' cellpadding='2'>n");
        if(
$this->showdate==true)print("    <tr bgcolor='".$this->daynamebgcolor."'><td colspan='7'><font face='".$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'><div align='center'>".$daynametextprefix.monthname($this->month,$this->year)." ".(($this->showyear)?$this->year:"").$daynametextsuffix."</div></font></td></tr>n");
        print(
"    <tr bgcolor='".$this->daynamebgcolor."'><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 1 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 2 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 3 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 4 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 5 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." 6 ".$daynametextsuffix."</font></td><td
               align='center'><font face='"
.$this->daynamefont."' color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix." S ".$daynametextsuffix."</font></td>");


        
$weekdaycount=0;
        for(
$daycount=$startday;$daycount<=$maxdays;$daycount++){
          if((
$weekdaycount%7)==0)print("</tr>n    <tr bgcolor='".$this->daybgcolor."'>");
          if(
$daycount>0){
            print(
"<td align='right'>");
            if(
$daycount!=$day){
              print(
"<font face='".$this->dayfont."' color='".$this->daycolor."' size='".$this->daysize."'>".$daytextprefix." ".$daycount." ".$daytextsuffix."</font>");
            } else print(
"<font face='".$this->dayfont."' color='".$this->dayactivecolor."' size='".$this->daysize."'>".$daytextprefix." ".$daycount." ".$daytextsuffix."</font>");
          } else print(
"<td>");
          print(
"</td>");
          
$weekdaycount++;
        }
        while(
$weekdaycount%7<>0){
          print(
"<td></td>");
          
$weekdaycount++;
        }
        print(
"</tr>n  </table>n");
        print(
"</td></tr></table>n");
  }
}

?>


Usage Example




Rate This Script





Search



This Category All Categories