/******************************************************************************************* Classe para manipulação de Datas ********************************************************************************************/ class Data { private $Dia; private $Mes; private $Ano; private $DiaErro; private $MesErro; private $AnoErro; function Data($d=1,$m=1,$a=1900){ $this->setDia((int)$d); $this->setMes((int)$m); $this->setAno((int)$a); } public function setDia($aux){ if(($aux<32)&&($aux>0)){ $this->Dia= $aux; $this->DiaErro=False; return True; } else{ $this->Dia=1; $this->DiaErro=True; return False; } } public function setMes($aux){ if(($aux<13)&&($aux>0)){ $this->Mes= $aux; $this->MesErro=False; return True; } else{ $this->Mes=1; $this->MesErro=True; return False; } } public function setAno($aux){ if(($aux<=2070)&&($aux>=1900)){ $this->Ano= $aux; $this->AnoErro=False; return True; } else{ $this->Ano=1900; $this->AnoErro=True; return False; } } public function getDia(){ return $this->Dia; } public function getMes(){ return $this->Mes; } public function getAno(){ return $this->Ano; } public function StrToData($aux){ if(strlen($aux)==10){ $d=(int) substr($aux,0,2); $m=(int) substr($aux,3,2); $a=(int) substr($aux,6,4); $this->Data($d,$m,$a); } else{ $this->Data(); return False; } } public function BDToData($aux){ if(strlen($aux)==10){ $a=(int) substr($aux,0,4); $m=(int) substr($aux,5,2); $d=(int) substr($aux,8,2); $this->Data($d,$m,$a); return True; } else{ $this->Data(); return False; } } public function getDiaErro(){ return $this->DiaErro; } public function getMesErro(){ return $this->MesErro; } public function getAnoErro(){ return $this->AnoErro; } //Erro = False nao tem erro public function Erro(){ if(($this->DiaErro==False)AND($this->MesErro==False)AND($this->AnoErro==False)) return False; else return True; } public function FormataPG(){ if($this->getDia()<10) $aux1="0".$this->getDia(); else $aux1=$this->getDia(); if($this->getMes()<10) $aux2="0".$this->getMes(); else $aux2=$this->getMes(); return $aux1 . "/" . $aux2 . "/" . $this->getAno(); } public function FormataBD(){ if($this->getDia()<10) $aux1="0".$this->getDia(); else $aux1=$this->getDia(); if($this->getMes()<10) $aux2="0".$this->getMes(); else $aux2=$this->getMes(); return $this->getAno() . "-" . $aux2 . "-" . $aux1; } }