Generic calendar

<?php
/**
* Generic calendar class.  Contains the variables
* and methods that are common to all calendar
* variations now and in the future.<br/>
* Variables:<br/>
* daysInMonth = array with month -> number of days pairs<br/>
* year = year the calendar is for<br/>
* dayOfWeekStart = what day does the 1st of January start at<br/>
*
* IMPORTANT: Method overloading is not possible. Therefore, getDays()
* and getDays($value) methods will crash program.
*
* @author David
*
*/
class CustomCalendar {
private $daysInMonth;
private $year;
private $dayOfWeekStart;

/**
* Set Calendar class with month->number of days value
* and the year.  Month is the first 3 letters of each month.
* Example January=jan, February=feb, etc… <br/>
* @param integer|array $y,$dim
* $y=year $dim=month-># of days pair
* @return nothing
* @author David
*/
function __construct($y, $dim) {
$this->setYear($y);
$this->setDaysInMonth($dim);
}

/**
* Set days in month with month -> day pairs<br/>
*
* @author David
* @param array $dim
* “first 3 letters of month” => # of
*  days in month pairs
* @return nothing
*/
function setDaysInMonth($dim) {
$this->daysInMonth=$dim;
}

/**
* Get all month -> day pairs<br/>
* return all months -> # of days pairs
*
* @author David
* @param none
* @return array
*/
function getDaysInMonth() {
return $this->daysInMonth;
}

/**
* Get days for a specific month only<br/>
* returns the # of days in the month specified
*
* @author David
* @param String $m
* first 3 letters of month to return the # of days
* @return integer
*/
function getDaysInAMonth($m) {
return $this->daysInMonth[$m];
}

/**
* Set the year of the calendar.
*
* @author David
* @param integer $y
* Year this calendar is for
* @return nothing
*/
function setYear($y) {
$this->year=$y;
}

/**
* Get the year of this calendar<br/>
* returns the year this calendar is for
*
* @author David
* @param none
* @return integer
*/
function getYear() {
return $this->year;
}

/**
* Get the day of the 1st of the month specified
* returns the day
* @param string $d
* $d is a string representation of the month
* @return string
* @author David
*/
function getDayOfWeekStart($d){
return $this->$dayOfWeekStart[$d];
}

/**
* Sets the variable dayOfWeekStart with the day that the
* 1st of each month lands on with $d being an array of
* month(key)=>day(value) pair.
* @param array $d
* @return nothing
* @author David
*/
function setDayOfWeekStart($d){
$this->dayOfWeekStart=($d);
}
}
?>

Leave a Reply