Convert Seconds to Numbers
This humble little script shows how seconds can be converted to words. There is a possibly 93737 ways of doing this, this is one of them.
<?php
/**
*
* make it or break it
*
*/error_reporting(E_ALL);
/**
*
* Class to convert seconds to words
*
*/class secs2words{
/**
*
* Declare the seconds variable
*
*/public $seconds;
/**
*
* @Constructor, duh!
*
* Access public
*
* @int seconds
*
* return void
*/function __construct($seconds){
$this->seconds=$seconds;
}
/**
*
* @make time function
*
* @access public
*
* @return string
*
*/
public function makeTime(){
if(!is_numeric($this->seconds) || $this->seconds > 999999999)
{
throw new exception("Value is out of range");
}
else
{
return $this->getHours($this->seconds).' Hours '.$this->getMinutes($this->seconds).' Minutes '.$this->getSeconds($this->seconds).' Seconds';
}
}
/**
*
* @ Divide seconds by 60
*
* @access private
*
* @return INT
*
*/private function getSeconds(){
return $this->seconds%60;
}
/**
*
* @ Convert seconds to minutes
*
* @access private
*
* @return INT
*
*/private function getMinutes(){
return (($this->seconds-$this->getSeconds())/60)%60;
}
/**
*
* @ Convert seconds to hours
*
* @access private
*
* @return INT
*
*/private function getHours($seconds){
return ((($this->seconds-$this->getSeconds())/60)-$this->getMinutes())/60;
}
} // end class
try{
if(isset($_POST['seconds']) && !empty($_POST['seconds']))
{
$obj= new secs2words($_POST['seconds']);
echo $obj->makeTime();
}
}
catch(Exception $e){
echo $e->getMessage();
}?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="seconds" maxlength="9" /><br />
<input type="submit" value="Convert" />
</form>
0 comments:
Post a Comment