<?php
function RelativeTimeString($timestamp) {
$minute = 60;
$hour = $minute * 60;
$day = $hour * 24;
$month = 30 * $day;
$year = 12 * $month;
if ($delta < 2 ) return 'Agorinha';
if ($delta < 1 * $minute) return "Há $delta segundos";
if ($delta < 2 * $minute) return 'Há um minuto';
if ($delta < 45 * $minute) return 'Há '.round($delta / $minute).' minutos'; if ($delta < 90 * $minute) return 'Há uma hora';
if ($delta < 24 * $hour) return 'Há '.round($delta / $hour).' horas'; if ($delta < 48 * $hour) return 'Ontem';
if ($delta < 30 * $day) return 'Há '.round($delta / $day).' dias'; if ($delta < 45 * $day) return 'Há um mês';
if ($delta < 12 * $month) return 'Há '.round($delta / $month).' meses'; if ($delta < 18 * $month) return 'Há um ano';
return 'Há '.round($delta / $year).' anos'; }
// Duas coisas: primeiro, cuidado com o cache do IDEONE,
// ele guarda o output de quando o código foi executado, e não visualizado
// segundo: o timezone do servidor do IDEONE provavelmente não bate com o seu,
// então faça testes com horários UTC.
echo RelativeTimeString
(mktime(0,0,0,5,31,2013)).PHP_EOL
; echo RelativeTimeString
(mktime(0,0,0,3,31,2017)).PHP_EOL
;
PD9waHAKCQoJZnVuY3Rpb24gUmVsYXRpdmVUaW1lU3RyaW5nKCR0aW1lc3RhbXApIHsKICAgICAgICAkbWludXRlID0gNjA7CiAgICAgICAgJGhvdXIgPSAkbWludXRlICogNjA7CiAgICAgICAgJGRheSA9ICRob3VyICogMjQ7CiAgICAgICAgJG1vbnRoID0gMzAgKiAkZGF5OwogICAgICAgICR5ZWFyID0gMTIgKiAkbW9udGg7CgogICAgICAgICRkZWx0YSA9IGZsb29yKHRpbWUoKS0kdGltZXN0YW1wKTsKICAgICAgICBpZiAoJGRlbHRhIDwgMiApICAgICAgICAgICByZXR1cm4gJ0Fnb3JpbmhhJzsKICAgICAgICBpZiAoJGRlbHRhIDwgMSAqICRtaW51dGUpICByZXR1cm4gIkjDoSAkZGVsdGEgc2VndW5kb3MiOwogICAgICAgIGlmICgkZGVsdGEgPCAyIC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