<?php
//
// the 'tiny date helper' class
//
class tdh { // tiny date helper
function MakeDate($string)
{
// formating string
$string = trim(ereg_replace("[A-Za-z]+"," ",trim($string)));
$string = trim(ereg_replace("[[:punct:]]"," ",$string));
$string = trim(ereg_replace("[,\.\|\/\-]"," ",$string));
$string = trim(ereg_replace("[[:space:]]{2,}","",$string));
$date_array = explode(" ",$string);
if(!is_array($date_array)){
$this->error = "coudn't find seperation sign";
return false;
}
// check year
if (count($date_array) == 2 OR (count($date_array) == 3 AND trim($date_array[2]) == "")){
$this->year = date(Y);
} elseif(count($date_array) == 3){
$this->year = $date_array[2];
if(strlen(trim($this->year)) == 2){
$this->year = substr(date(Y),0,2).$this->year;
} elseif(strlen(trim($this->year)) != 4){
$message = " coudn't understand the date .<br> just try it like 'TT-MM-JJ'<br>";
$this->error = $message;
return false;
}
} else {
$message = "coudn't understand the date .<br> just try it like 'TT-MM-JJ'<br>";
$this->error = $message;
return false;
}
// check month
if (strlen(trim($date_array[1])) == 1){
$this->month = "0".trim($date_array[1]);
} else {
$this->month = trim($date_array[1]);
}
// check day
if (strlen(trim($date_array[0])) == 1){
$this->day = "0".trim($date_array[0]);
} else {
$this->day = trim($date_array[0]);
}
/* check whole date */
if(checkdate ($this->month, $this->day, $this->year) === false){
$this->error = "no valid date";
return false;
} else {
$this->string = $string;
$this->date = $this->day.".".$this->month.".".$this->year;
$this->timestamp = mktime(0,0,0,$this->month,$this->day,$this->year);
$this->mysql_stamp = $this->year."-".$this->month."-".$this->day;
return true;
}
}
} // end tdh class
?>