From e88ae54bef268e455b6d6028a697e9dbd98a7853 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 7 Dec 2024 20:41:13 +0000 Subject: [PATCH] add more indicators and a new function to return relative time in the past and the future --- Zotlabs/Lib/ThreadItem.php | 6 +++--- include/datetime.php | 34 ++++++++++++++++++++++++++++++++++ view/tpl/conv_item.tpl | 9 ++++++--- view/tpl/conv_list.tpl | 9 ++++++--- view/tpl/search_item.tpl | 16 +++++++++++----- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index ae5954a62..4b833f4b4 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -414,11 +414,11 @@ class ThreadItem { 'str_app' => sprintf( t('from %s'), $item['app']), 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created']), - 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('Last edited %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'])) : ''), - 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf( t('Expires %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'])) : ''), + 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('Last edited %s'), relative_time($item['edited'])) : ''), + 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires %s'), relative_time($item['expires'])) : ''), 'lock' => $lock, 'locktype' => $locktype, - 'delayed' => $item['item_delayed'], + 'delayed' => (($item['item_delayed']) ? sprintf(t('Published %s'), relative_time($item['created'])) : ''), 'privacy_warning' => $privacy_warning, 'verified' => $verified, 'unverified' => $unverified, diff --git a/include/datetime.php b/include/datetime.php index 2182d7c43..e23a11741 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -268,6 +268,40 @@ function relative_date($posted_date, $format = null) { return $abs; } + +function relative_time($timestamp) { + $timestamp = datetime_convert('UTC', date_default_timezone_get(), $timestamp); + + $now = new DateTime(); + $time = new DateTime($timestamp); + + $interval = $now->diff($time); + + $prefix = ''; + $appendix = ' ' . t('ago'); + + if ($time > $now) { + $prefix = t('in') . ' '; + $appendix = ''; + } + + if ($interval->y > 0) { + return $prefix . $interval->y . ' ' . plural_dates('y', $interval->y) . $appendix; + } elseif ($interval->m > 0) { + return $prefix . $interval->m . ' ' . plural_dates('m', $interval->m) . $appendix; + } elseif ($interval->d > 0) { + return $prefix . $interval->d . ' ' . plural_dates('d', $interval->d) . $appendix; + } elseif ($interval->h > 0) { + return $prefix . $interval->h . ' ' . plural_dates('h', $interval->h) . $appendix; + } elseif ($interval->i > 0) { + return $prefix . $interval->i . ' ' . plural_dates('i', $interval->i) . $appendix; + } elseif ($interval->s > 0) { + return $prefix . $interval->s . ' ' . plural_dates('s', $interval->s) . $appendix; + } else { + return t('now'); + } +} + function plural_dates($k,$n) { switch($k) { diff --git a/view/tpl/conv_item.tpl b/view/tpl/conv_item.tpl index 56f590284..96e6f57df 100644 --- a/view/tpl/conv_item.tpl +++ b/view/tpl/conv_item.tpl @@ -32,9 +32,6 @@ {{if $item.location}} {{$item.location}} {{/if}} - {{if $item.delayed}} - - {{/if}} {{if $item.editedtime}} {{/if}} @@ -46,6 +43,12 @@ {{if $item.no_comment}} {{/if}} + {{if $item.delayed}} + + {{/if}} + {{if $item.expiretime}} + + {{/if}} {{if $item.expiretime}} {{$item.expiretime}}{{/if}} {{if $item.thr_parent_uuid}} diff --git a/view/tpl/conv_list.tpl b/view/tpl/conv_list.tpl index f31424ce3..6143e156e 100644 --- a/view/tpl/conv_list.tpl +++ b/view/tpl/conv_list.tpl @@ -26,9 +26,6 @@ {{if $item.location}} {{$item.location}} {{/if}} - {{if $item.delayed}} - - {{/if}} {{if $item.editedtime}} {{/if}} @@ -40,6 +37,12 @@ {{if $item.no_comment}} {{/if}} + {{if $item.delayed}} + + {{/if}} + {{if $item.expiretime}} + + {{/if}} {{if $item.expiretime}} {{$item.expiretime}}{{/if}} {{if $item.pinned}} diff --git a/view/tpl/search_item.tpl b/view/tpl/search_item.tpl index 709e40a13..d693c4d37 100644 --- a/view/tpl/search_item.tpl +++ b/view/tpl/search_item.tpl @@ -26,18 +26,24 @@ {{if $item.location}} {{$item.location}} {{/if}} - {{if $item.delayed}} - - {{/if}} {{if $item.editedtime}} - + {{/if}} {{if $item.verified}} {{elseif $item.forged}} {{/if}} - {{if $item.editedtime}} {{$item.editedtime}}{{/if}}{{if $item.expiretime}} {{$item.expiretime}}{{/if}} + {{if $item.no_comment}} + + {{/if}} + {{if $item.delayed}} + + {{/if}} + {{if $item.expiretime}} + + {{/if}} + {{if $item.expiretime}} {{$item.expiretime}}{{/if}} {{if $item.pinned}}