par
rimie » 12 mars 2013, 01:26
voici le code de la class:
<?php
class DOBD {
// params
private $errors = array(), $day, $month, $year;
// get user group, level and id
public function __construct($day, $month, $year) {
// set months with 31 days
$mw31d = array(1, 3, 5, 7, 8, 10, 12);
$this->day = $day;
$this->month = $month;
$this->year = $year;
$this->mw31d = $mw31d;
} // end function __construct
// check the day
public function checkDay() {
// check if Feb contains more than 29 days
if(empty($this->day) OR ($this->day > 31))
{
$day_check = 'DayNotValid';
}
elseif(($this->day > 29) && ($this->month == 02))
{
$day_check = 'Daybad29';
}
else
{
$day_check = 'DayValid';
}
$this->day_check = $day_check;
//echo 'check day '.$this->day_check.'<br />';
return $this->day_check;
} // end function checkDay($this->day)
public function __toString()
{
return $this->day;
}
// check the month
public function checkMonth() {
var_dump($this->day);
if(empty($this->month) OR ($this->month > 12))
{
$month_check = 'MonthNotValid';
}
// check if the selected month has 31 days
elseif(($this->day > 30) && (!in_array($this->month, $this->mw31d)))
{
$month_check = 'Monthbad31';
}
else
{
$month_check = 'MonthValid';
}
$this->month_check = $month_check;
return $this->month_check;
//echo 'check month '.$this->month_check.'<br />';
} // end function checkMonth($this->month)
// check Leap year
public function isLeap()
{
if(((($this->year % 4) == 0) AND ($this->year % 100 != 0)) OR ($this->year % 400 == 0))
{
return TRUE;
}
return FALSE;
}
// check the year
public function checkYear() {
if(empty($this->year))
{
$year_check = 'YearNotValid';
}
// check if the year is leap
elseif((!$this->isLeap($this->year) && ($this->day >= 29) && ($this->month == 2)))
{
$year_check = 'yearLeap';
}
else
{
$year_check = 'YearValid';
}
$this->year_check = $year_check;
return $this->year_check;
//echo 'check year '.$this->year_check.'<br />';
} // end function checkYear($this->year) {
// check if the DOB is greater than today date (NOT YET BORNED)
public function checkDOBD()
{
$today = date('d-m-Y');
$todayTimeStamp = strtotime($today);
//echo $todayTimeStamp.'<br >';
$dob = $this->day.'-'.$this->month.'-'.$this->year;
$dobTimeStamp = strtotime($dob).'<br />';
//echo $dobTimeStamp.'<br >';
if($todayTimeStamp <= $dobTimeStamp)
{
$dob_check = 'NotYetBorn';
//return false;
}
elseif(($this->year_check != 'YearValid') OR ($this->month_check != 'MonthValid') OR ($this->day_check != 'DayValid'))
{
$dob_check = 'DOBNotValid';
//return false;
}
else
{
$dob_check = 'DOBValid';
//return true;
}
$this->dob_check = $dob_check;
//echo 'so dobd is ===> '.$this->dob_check.'<br />';
return $this->dob_check;
} // end function checkDOBD()
} // end class DOBD
?>
voici le code de la class:
[php]
<?php
class DOBD {
// params
private $errors = array(), $day, $month, $year;
// get user group, level and id
public function __construct($day, $month, $year) {
// set months with 31 days
$mw31d = array(1, 3, 5, 7, 8, 10, 12);
$this->day = $day;
$this->month = $month;
$this->year = $year;
$this->mw31d = $mw31d;
} // end function __construct
// check the day
public function checkDay() {
// check if Feb contains more than 29 days
if(empty($this->day) OR ($this->day > 31))
{
$day_check = 'DayNotValid';
}
elseif(($this->day > 29) && ($this->month == 02))
{
$day_check = 'Daybad29';
}
else
{
$day_check = 'DayValid';
}
$this->day_check = $day_check;
//echo 'check day '.$this->day_check.'<br />';
return $this->day_check;
} // end function checkDay($this->day)
public function __toString()
{
return $this->day;
}
// check the month
public function checkMonth() {
var_dump($this->day);
if(empty($this->month) OR ($this->month > 12))
{
$month_check = 'MonthNotValid';
}
// check if the selected month has 31 days
elseif(($this->day > 30) && (!in_array($this->month, $this->mw31d)))
{
$month_check = 'Monthbad31';
}
else
{
$month_check = 'MonthValid';
}
$this->month_check = $month_check;
return $this->month_check;
//echo 'check month '.$this->month_check.'<br />';
} // end function checkMonth($this->month)
// check Leap year
public function isLeap()
{
if(((($this->year % 4) == 0) AND ($this->year % 100 != 0)) OR ($this->year % 400 == 0))
{
return TRUE;
}
return FALSE;
}
// check the year
public function checkYear() {
if(empty($this->year))
{
$year_check = 'YearNotValid';
}
// check if the year is leap
elseif((!$this->isLeap($this->year) && ($this->day >= 29) && ($this->month == 2)))
{
$year_check = 'yearLeap';
}
else
{
$year_check = 'YearValid';
}
$this->year_check = $year_check;
return $this->year_check;
//echo 'check year '.$this->year_check.'<br />';
} // end function checkYear($this->year) {
// check if the DOB is greater than today date (NOT YET BORNED)
public function checkDOBD()
{
$today = date('d-m-Y');
$todayTimeStamp = strtotime($today);
//echo $todayTimeStamp.'<br >';
$dob = $this->day.'-'.$this->month.'-'.$this->year;
$dobTimeStamp = strtotime($dob).'<br />';
//echo $dobTimeStamp.'<br >';
if($todayTimeStamp <= $dobTimeStamp)
{
$dob_check = 'NotYetBorn';
//return false;
}
elseif(($this->year_check != 'YearValid') OR ($this->month_check != 'MonthValid') OR ($this->day_check != 'DayValid'))
{
$dob_check = 'DOBNotValid';
//return false;
}
else
{
$dob_check = 'DOBValid';
//return true;
}
$this->dob_check = $dob_check;
//echo 'so dobd is ===> '.$this->dob_check.'<br />';
return $this->dob_check;
} // end function checkDOBD()
} // end class DOBD
?>
[/php]