# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . define('TSMINUTE', 60); define('TSHOUR', 3600); define('TSHALFHOUR', 1800); define('TSHOURANDHALF', TSHOUR+TSHALFHOUR); define('TSDAY', 86400); function showTimeAgo($timestamp) { $diff = time() - (int) $timestamp; if($diff <= 1) { return 'ahora mismo'; } elseif ($diff < 60) { $string = "hace $diff segundos"; return $string; } elseif ($diff < TSHOUR) { $mdiff = round($diff / TSMINUTE); $string = "hace $mdiff minutos"; return $string; } elseif (($diff / TSHOUR) >= 1 && ($diff / TSHOUR) < 24) { $mdiff = ($diff / TSHOUR); $half = round($mdiff) !== floor($mdiff); $floor = floor($mdiff); if($half) { if($floor == 1) // $string = __("about one hour and half ago"); $string = "hace una hora"; else // $string = sprintf(__("about %s hours and half ago"), $floor); $string = "hace $floor horas"; } else { if($floor == 1) $string = "hace una hora"; else // $string = sprintf(__("about %s hours ago"), $floor); $string = "hace $floor horas"; } return $string; } elseif (($diff / TSDAY) >= 1 && ($diff / TSDAY) < 25) { $mdiff = ($diff / TSDAY); $half = round($mdiff) !== floor($mdiff); $floor = floor($mdiff); if($half) { if($floor == 1) // $string = __("about one day and half ago"); $string = "hace un día"; else // $string = sprintf(__("about %s days and half ago"), $floor); $string = "hace $floor días"; } else { if($floor == 1) $string = "hace un día"; else // $string = sprintf(__("about %s days ago"), $floor); $string = "hace $floor días"; } return $string; } else { $date = 'el '.date('d/m/Y', $timestamp).' a las '.date('H:i', $timestamp); return $date; } }