<?php
// Creamos el objeto instanciando la clase Timefull en la variable
$ingreso_tiempo = new Timefull;
//Llamamos a la funcion, colocando los parametros correctos
echo $ingreso_tiempo -> getTime ( '5 hour' , 'secs' ) ;
// Resultado -> 18000 seconds
//Si no se especifica el parametro de la unidad a convertir, se autoasignara uno que por defecto son segundos
echo $ingreso_tiempo -> getTime ( '1 hour' ) ;
// Resultado -> 3600 seconds
//Es posible colocar prefijos para las unidades de tiempo y no es preciso colocar en singular o plural los mismas, un ejemplo:
echo $ingreso_tiempo -> getTime ( '3601 mins' , 'hour' ) ;
// Resultado -> 60 hours 1 minute
//Para obtener directamente la operacion de conversion a la unidad de tiempo especificada, debera colocarse como tercer parametro el boolean 'true', aqui un ejemplo:
echo $ingreso_tiempo -> getTime ( '3601 mins' , 'hour' , true ) ;
// Resultado -> 60.01667 hours
//Si se ingresa una unidad cuyo valor no es igual o mayor al valor que definiria la siguiente unidad a esta, la funcion traera como resultado el mismo valor sin transformarse:
//Dado que 45 segundos no es el valor que tiene un minuto entonces la funcion traera los 45 segundos ingresados
echo $ingreso_tiempo -> getTime ( '45 secs' , 'minutes' ) ;
//Resultado-> 45 seconds;
//Si se desea obtener sin importar el valor de la unidad ingresada, el valor de la unidad a transformar, colocar como tercer parametro el boolean 'true'
echo $ingreso_tiempo -> getTime ( '45 secs' , 'minutes' , true ) ;
//Resultado-> 0.75000 minutes
// Otros ejemplos
echo $ingreso_tiempo -> getTime ( '4564 seconds' , 'hours' ) ;
// Resultado -> 1 hour 16 minutes 4 seconds
//Recordar que los parametros a ingresar como unidades de tiempo deben ser en ingles y estos pueden ser secs o seconds (singular o plural) para segundos, mins o minutes (singular o plural) para minutos y hour o hours (singular o plural) para horas.
/************************************************************************************************
CODIGO FUENTE DE LA CLASE
*************************************************************************************************/
class Timefull
{
public $def_return = [ 's' => 'second' , 'm' => 'minute' , 'h' => 'hour' , 'seconds' , 'minutes' , 'hours' , 'min' , 'sec' , 'mins' , 'secs' ] ;
public $def_time ;
public $def_transform ;
public $time ;
public $seconds ;
public $minutes ;
public $hours ;
public $error ;
private $raw ;
public function getTime( $time = null , $def_transform = null , $raw = false ) {
$this -> raw = ( $raw ) ? true : false ;
if ( $time != null ) {
return $this -> evaluateTime ( $def_transform ) ;
}
}
public function evaluateTime( $def_transform ) {
for ( $i = 0 , $s = count ( $split ) ; $i < $s ; $i ++ ) { $this -> time .= $split [ $i ] ; } else if ( ( $split [ $i ] == ',' ) || ( $split [ $i ] == '.' ) ) {
} else {
break ;
}
}
return $this -> transformTime ( $def_transform ) ;
}
}
public function transformTime( $def_transform ) {
if ( $def_transform ) {
$def_transform = ( in_array ( $def_transform , $this -> def_return ) ) ?
$def_transform : $this -> autoDef ( true ) ; } else {
$def_transform = $this -> autoDef ( ) ;
}
if ( $this -> error ) { return $this -> error ; exit ; } $this -> def_transform = $def_transform ;
$time_transform = $this -> evaluateTransform ( ) ;
for ( $i = 0 , $s = count ( $time_transform [ 'time' ] ) ; $i < $s ; $i ++ ) { $return [ ] = ( $time_transform [ 'time' ] [ $i ] > 1 ) ? "{$time_transform ['time'][$i ]} {$time_transform ['def'][$i ]}s " : "{$time_transform ['time'][$i ]} {$time_transform ['def'][$i ]} " ;
}
} else {
if ( $time_transform [ 'time' ] > 1 || $time_transform [ 'time' ] > 0.1 ) {
return "{$time_transform['time']} {$time_transform['def']} s" ;
} else {
return "{$time_transform['time']} {$time_transform['def']} " ;
}
}
}
public function evaluateTransform( ) {
if ( preg_match ( "/\bsec(s?|ond(s?))?\b/i" , $this -> def_time ) ) { return $this -> seconds ( ) ; } if ( preg_match ( "/\bmin(s?|ute(s?))?\b/i" , $this -> def_time ) ) { return $this -> minutes ( ) ; } if ( preg_match ( "/\bhour(s?)\b/i" , $this -> def_time ) ) { return $this -> hours ( ) ; } }
public function seconds( $retry = false ) {
if ( ( preg_match ( "/\bsec(s?|ond(s?))?\b/i" , $this -> def_transform ) ) || $retry ) { $this -> seconds = $this -> time ; return [ 'time' => $this -> seconds , 'def' => $this -> def_return [ 's' ] ] ;
} else {
if ( preg_match ( "/\bmin(s?|ute(s?))?\b/i" , $this -> def_transform ) ) return $this -> secondsMinutes ( ) ; if ( preg_match ( "/\bhour(s?)\b/i" , $this -> def_transform ) ) return $this -> secondsHours ( ) ; }
}
public function minutes( $retry = false ) {
if ( ( preg_match ( "/\bmin(s?|ute(s?))?\b/i" , $this -> def_transform ) ) || $retry ) { $this -> minutes = $this -> time ; return [ 'time' => $this -> minutes , 'def' => $this -> def_return [ 'm' ] ] ;
} else {
if ( preg_match ( "/\bsec(s?|ond(s?))?\b/i" , $this -> def_transform ) ) return $this -> minutesSeconds ( ) ; if ( preg_match ( "/\bhour(s?)\b/i" , $this -> def_transform ) ) return $this -> minutesHours ( ) ; }
}
public function hours( ) {
if ( preg_match ( "/\bhour(s?)\b/i" , $this -> def_transform ) ) { $this -> hours = $this -> time ; return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
} else {
if ( preg_match ( "/\bsec(s?|ond(s?))?\b/i" , $this -> def_transform ) ) return $this -> hoursSeconds ( ) ; if ( preg_match ( "/\bmin(s?|ute(s?))?\b/i" , $this -> def_transform ) ) return $this -> hoursMinutes ( ) ; }
}
public function secondsMinutes( ) {
if ( ! $this -> raw ) {
if ( $time > 59 ) {
$this -> minutes = ( int
) floor ( $time / 60 ) ; $this -> seconds = ( int) $time - ( $this -> minutes * 60 ) ;
if ( $this -> seconds == 0 ) {
return [ 'time' => $this -> minutes , $this -> def_return [ 'm' ] ] ;
} else {
return [ 'time' => [ $this -> minutes , $this -> seconds ] , 'def' => [ $this -> def_return [ 'm' ] , $this -> def_return [ 's' ] ] ] ;
}
} else {
return $this -> seconds ( true ) ;
}
} else {
$this -> minutes = ( int
) floor ( $time / 60 ) ; return [ 'time' => $this -> minutes , 'def' => $this -> def_return [ 'm' ] ] ;
} else {
return [ 'time' => $this -> minutes , 'def' => $this -> def_return [ 'm' ] ] ;
}
}
}
public function secondsHours( ) {
if ( ! $this -> raw ) {
if ( $time > 59 && $time < 3600 ) {
return $this -> secondsMinutes ( ) ;
} else if ( $time > 3599 ) {
$this -> hours = ( int
) floor ( $time / 3600 ) ; $this -> minutes = ( int
) floor ( ( $time - ( $this -> hours * 3600 ) ) / 60 ) ; $this -> seconds = ( int) ( ( $time - ( $this -> hours * 3600 ) ) - ( $this -> minutes * 60 ) ) ;
if ( $this -> minutes == 0 && $this -> seconds == 0 ) {
return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
} else if ( $this -> minutes != 0 && $this -> seconds == 0 ) {
return [ 'time' => [ $this -> hours , $this -> minutes ] , 'def' => [ $this -> def_return [ 'h' ] , $this -> def_return [ 'm' ] ] ] ;
} else if ( $this -> minutes == 0 && $this -> seconds != 0 ) {
return [ 'time' => [ $this -> hours , $this -> seconds ] , 'def' => [ $this -> def_return [ 'h' ] , $this -> def_return [ 's' ] ] ] ;
} else {
return [ 'time' => [ $this -> hours , $this -> minutes , $this -> seconds ] , 'def' => [ $this -> def_return [ 'h' ] , $this -> def_return [ 'm' ] , $this -> def_return [ 's' ] ] ] ;
}
} else {
return $this -> seconds ( true ) ;
}
} else {
$this -> hours = ( int
) floor ( $time / 3600 ) ; return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
} else {
return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
}
}
}
public function minutesSeconds( ) {
if ( ! $this -> raw ) {
$this -> seconds = ( int) ( $time * 60 ) ;
return [ 'time' => $this -> seconds , 'def' => $this -> def_return [ 's' ] ] ;
} else {
$this -> seconds = ( $time * 60 ) ;
return [ 'time' => $this -> seconds , 'def' => $this -> def_return [ 's' ] ] ;
}
}
public function minutesHours( ) {
if ( ! $this -> raw ) {
if ( $time > 59 ) {
$this -> hours = ( int
) floor ( $time / 60 ) ; $this -> minutes = ( int
) floor ( $time - ( $this -> hours * 60 ) ) ; if ( $this -> minutes == 0 ) {
return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
} else {
return [ 'time' => [ $this -> hours , $this -> minutes ] , 'def' => [ $this -> def_return [ 'h' ] , $this -> def_return [ 'm' ] ] ] ;
}
} else {
return $this -> minutes ( true ) ;
}
} else {
$this -> hours = ( int
) floor ( $time / 60 ) ; return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
} else {
return [ 'time' => $this -> hours , 'def' => $this -> def_return [ 'h' ] ] ;
}
}
}
public function hoursSeconds( ) {
if ( ! $this -> raw ) {
$this -> seconds = ( int) ( $time * 3600 ) ;
return [ 'time' => $this -> seconds , 'def' => $this -> def_return [ 's' ] ] ;
} else {
$this -> seconds = ( $time * 3600 ) ;
return [ 'time' => $this -> seconds , 'def' => $this -> def_return [ 's' ] ] ;
}
}
public function hoursMinutes( ) {
if ( ! $this -> raw ) {
$this -> minutes = ( int) ( $time * 60 ) ;
return [ 'time' => $this -> minutes , 'def' => $this -> def_return [ 'm' ] ] ;
} else {
$this -> minutes = ( $time * 60 ) ;
return [ 'time' => $this -> minutes , 'def' => $this -> def_return [ 'm' ] ] ;
}
}
public function autoDef( $error = false ) {
if ( $error ) {
$this -> error = 'IS NOT A CORRECT VALUE TO TRANSFORM!' ;
} else {
return 'seconds' ;
}
}
}
PD9waHAKCi8vIENyZWFtb3MgZWwgb2JqZXRvIGluc3RhbmNpYW5kbyBsYSBjbGFzZSBUaW1lZnVsbCBlbiBsYSB2YXJpYWJsZQokaW5ncmVzb190aWVtcG8gPSBuZXcgVGltZWZ1bGw7CiAKLy9MbGFtYW1vcyBhIGxhIGZ1bmNpb24sIGNvbG9jYW5kbyBsb3MgcGFyYW1ldHJvcyBjb3JyZWN0b3MKZWNobyAkaW5ncmVzb190aWVtcG8tPmdldFRpbWUoJzUgaG91cicsJ3NlY3MnKTsKLy8gUmVzdWx0YWRvIC0+IDE4MDAwIHNlY29uZHMKIAovL1NpIG5vIHNlIGVzcGVjaWZpY2EgZWwgcGFyYW1ldHJvIGRlIGxhIHVuaWRhZCBhIGNvb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KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCgpDT0RJR08gRlVFTlRFIERFIExBIENMQVNFCgoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwogCmNsYXNzIFRpbWVmdWxsCnsKIAoJcHVibGljICRkZWZfcmV0dXJuID0gWydzJz0+J3NlY29uZCcsJ20nPT4nbWludXRlJywnaCc9Pidob3VyJywnc2Vjb25kcycsJ21pbnV0ZXMnLCdob3VycycsJ21pbicsJ3NlYycsJ21pbnMnLCdzZWNzJ107CglwdWJsaWMgJGRlZl90aW1lOwoJcHVibGljICRkZWZfdHJhbnNmb3JtOwoJcHVibGljICR0aW1lOwoJcHVibGljICRzZWNvbmRzOwoJcHVibGljICRtaW51dGVzOwoJcHVibGljICRob3VyczsKCXB1YmxpYyAkZXJyb3I7Cglwcml2YXRlICRyYXc7CiAKICAgICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRUaW1lKCR0aW1lID0gbnVsbCwkZGVmX3RyYW5zZm9ybSA9IG51bGwsJHJhdyA9IGZhbHNlKXsKCQkkdGhpcy0+cmF3ID0gKCRyYXcpID8gdHJ1ZSA6IGZhbHNlIDsKCQlpZiAoJHRpbWUgIT0gbnVsbCl7CgkJCSR0aGlzLT50aW1lID0gdHJpbSgkdGltZSk7CgkJCXJldHVybiAkdGhpcy0+ZXZhbHVhdGVUaW1lKCRkZWZfdHJhbnNmb3JtKTsKCQl9Cgl9CiAKCXB1YmxpYyBmdW5jdGlvbiBldmFsdWF0ZVRpbWUoJGRlZl90cmFuc2Zvcm0pewoJCWlmICgkdGhpcy0+dGltZSl7CgkJCSRzcGxpdCA9IHN0cl9zcGxpdCgkdGhpcy0+dGltZSk7CgkJCSR0aGlzLT50aW1lID0gbnVsbDsKCQkJZm9yICgkaT0wLCRzPWN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