diff --git a/vendor/PicoTools/Helper.php b/vendor/PicoTools/Helper.php index a3ea708..26c8564 100644 --- a/vendor/PicoTools/Helper.php +++ b/vendor/PicoTools/Helper.php @@ -77,6 +77,30 @@ function in_list($id, array $listing) return '?'; } +function relative_time($date, $postfix = ' ago', $fallback = '%e %B %Y %k:%M') +{ + $diff = time() - strtotime($date); + if($diff < 60) + return $diff . ' second'. ($diff != 1 ? 's' : '') . $postfix; + $diff = round($diff/60); + if($diff < 60) + return $diff . ' minute'. ($diff != 1 ? 's' : '') . $postfix; + $diff = round($diff/60); + if($diff < 24) + return $diff . ' hour'. ($diff != 1 ? 's' : '') . $postfix; + $diff = round($diff/24); + if($diff < 7) + return $diff . ' day'. ($diff != 1 ? 's' : '') . $postfix; + $diff = round($diff/7); + if($diff < 4) + return $diff . ' week'. ($diff != 1 ? 's' : '') . $postfix; + $diff = round($diff/4); + if($diff < 12) + return $diff . ' month'. ($diff != 1 ? 's' : '') . $postfix; + + return date($fallback, strtotime($date)); +} + function error_class(array $errors, $name) { return ! isset($errors[$name]) ? '' : ' form-error'; @@ -208,4 +232,4 @@ function form_email($name, $values = array(), array $errors = array(), array $at function form_date($name, $values = array(), array $errors = array(), array $attributes = array(), $class = '') { return form_input('date', $name, $values, $errors, $attributes, $class); -} \ No newline at end of file +}