Created
July 26, 2021 20:04
-
-
Save joelmiguelvalente/1a4f51e683099b8557779bb6fbc41323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Smarty plugin | |
* @package Smarty | |
* @subpackage plugins | |
*/ | |
/** | |
* Smarty cat modifier plugin | |
* | |
* Type: modifier<br> | |
* Name: hace<br> | |
* Date: Feb 24, 2010 | |
* Purpose: catenate a value to a variable | |
* Input: string to catenate | |
* Example: {$var|cat:"foo"} | |
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat | |
* (Smarty online manual) | |
* @author Ivan Molina Pavana | |
* @version 1.0 | |
* @param string | |
* @param string | |
* @return string | |
*/ | |
function smarty_modifier_hace($fecha, $show = false){ | |
$ahora = time(); | |
$tiempo = $ahora - $fecha; | |
// | |
$dias = round($tiempo / 86400); | |
// HOY | |
if($dias <= 0) { | |
// HACE MENOS DE 1 HORA | |
if(round($tiempo / 3600) <= 0){ | |
// HACE MENOS DE 1 MINUTO | |
if(round($tiempo / 60) <= 0){ | |
if($tiempo <= 60){ $hace = "Hace unos segundos"; } | |
// HACE X MINUTOS | |
} else { | |
$can = round($tiempo / 60); | |
$word = ($can <= 1) ? "minuto" : "minutos"; | |
$hace = 'Hace '.$can. " ".$word; | |
} | |
// HACE X HORAS | |
} else { | |
$can = round($tiempo / 3600); | |
$word = ($can <= 1) ? "hora" : "horas"; | |
$hace = 'Hace '.$can. " ".$word; | |
} | |
} | |
// MENOS DE 7 DIAS | |
else if($dias <= 30){ | |
// AYER | |
$hace = ($dias < 2) ? 'Ayer' : 'Hace '.$dias.' días'; | |
// HACE MAS DE UNA SEMANA | |
} else{ | |
$meses = round($tiempo / 2592000); | |
if($meses == 1) $hace = 'Más de 1 mes'; | |
elseif($meses < 12) { | |
$hace = 'Más de '.$meses.' meses'; | |
} else { | |
$anos = round($tiempo / 31536000); | |
$hace = ($anos == 1) ? 'Más de un año' : 'Más de '.$anos.' años'; | |
} | |
} | |
// | |
return $hace; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment