During my PHP / MySQL Class (which btw is beginners stuff doesnt really get advanced unless a members login is considered advanced) i decided to create something.
Anyway i decided to create a CountDown class, its not 100% dead accurate or displays things very correctly at this point, so a little work needed but what do you guys think.
<?php
class countDown
{
var $day;
var $month;
var $year;
var $isFalse = true;
var $showError;
function countDown($day,$month,$year,$showerror=1)
{
//if an error needs to be displayed 1 = yes 0 = no output
$this->showError = $showerror;
$day = (int)$day;
$month = (int)$month;
$year = (int)$year;
$tempVal = $day."-".$month."-".$year;
if (preg_match("/\d{1,2}-\d{1,2}-\d{4}/i",$tempVal))
{
if (checkdate($month,$day,$year))
{
$dateTime = $this->timeFormat($day,$month,$year);
$currentTime = $this->timeFormat(date('d'),date('m'),date('Y'));
if (($dateTime-$currentTime) <= 1)
{
$this->errorDisplay("Date already passed");
$this->isFalse = false;
return false;
}
else
{
$this->day = $day;
$this->month = $month;
$this->year = $year;
return true;
}
}
else
{
$this->errorDisplay("Date Doesnt Exist");
$this->isFalse = false;
return false;
}
}
}
/*
Make sure class status is ok
If false (isFalse) an invalid value has been put into the class
*/
function checkStatus()
{
return ($this->isFalse!=false)?true:false;
}
/*
Return the unix timestamp of the current time
*/
function timeFormat($day='',$month='',$year='',$hour='0',$minute='0',$second='0')
{
if (($time=mktime($hour,$minute,$second,$month,$day,$year))<1)
{
$this->errorDisplay("Unknown Error");
$this->isFalse = false;
return false;
}
else
{
return $time;
}
}
function days()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
return array(
"days"=>floor(($countTo-$currentTime)/86400)
);
}
}
function daysHours()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
$dayEnd = strtotime("tomorrow");
return array(
"days"=> floor(($countTo-$currentTime)/86400),
"hours" => floor(($dayEnd-$currentTime)/3600)
);
}
}
function daysHoursMinutes()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
$dayEnd = strtotime("tomorrow");
return array(
"days"=> floor(($countTo-$currentTime)/86400),
"hours" => floor(($dayEnd-$currentTime)/3600),
"minutes" => 60-date("i")
);
}
}
function weeksDaysHoursMinutes()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
$dayEnd = strtotime("tomorrow");
return array(
"weeks" => floor(($countTo-time())/604800),
"days" => floor(($countTo-$currentTime)/86400),
"hours" => floor(($dayEnd-$currentTime)/3600),
"minutes" => 60-date("i")
);
}
}
function weeksDaysHours()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
$dayEnd = strtotime("tomorrow");
return array(
"weeks" => floor(($countTo-time())/604800),
"days" => floor(($countTo-$currentTime)/86400),
"hours" => floor(($dayEnd-$currentTime)/3600)
);
}
}
function weeksDays()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
return array(
"weeks" => floor(($countTo-time())/604800),
"days" => floor(($countTo-$currentTime)/86400)
);
}
}
function weeks()
{
if ($this->checkStatus()!=false)
{
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
return array("weeks" => floor(($countTo-time())/604800));
}
}
function monthDays()
{
if ($this->checkStatus()!=false)
{
$currentTime = time();
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
return array(
"months" => floor(($countTo-$currentTime)/2592000),
"days" => floor(($countTo-$currentTime)/86400)
);
}
}
function months()
{
if ($this->checkStatus()!=false)
{
$countTo = $this->timeFormat($this->day,$this->month,$this->year);
return array("months" => floor(($countTo-time())/2592000));
}
}
function errorDisplay($msg)
{
if ($this->showError==1)
{
echo $msg;
}
}
}
$count = new countDown(11,11,2004);
if ($count->checkStatus()!=false)
{
print_r($count->weeksDaysHoursMinutes());
}
?>
P.S.
(if youd rather it be attached ill do so)