mirror of
https://github.com/friendica/friendica
synced 2024-11-09 23:02:54 +00:00
Merge pull request #12383 from annando/issue-12367
Issue 12367: Calculate relative date on "date" level instead of "datetime"
This commit is contained in:
commit
183e9dc7b2
2 changed files with 14 additions and 6 deletions
|
@ -137,7 +137,7 @@ abstract class BaseUsers extends BaseModeration
|
||||||
$user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
|
$user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
|
||||||
|
|
||||||
$user['register_date'] = Temporal::getRelativeDate($user['register_date']);
|
$user['register_date'] = Temporal::getRelativeDate($user['register_date']);
|
||||||
$user['login_date'] = Temporal::getRelativeDate($user['last-activity']);
|
$user['login_date'] = Temporal::getRelativeDate($user['last-activity'], null, false);
|
||||||
$user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
|
$user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
|
||||||
$user['is_admin'] = in_array($user['email'], $adminlist);
|
$user['is_admin'] = in_array($user['email'], $adminlist);
|
||||||
$user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != $this->session->getLocalUserId();
|
$user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != $this->session->getLocalUserId();
|
||||||
|
|
|
@ -305,13 +305,14 @@ class Temporal
|
||||||
* Results relative to current timezone.
|
* Results relative to current timezone.
|
||||||
* Limited to range of timestamps.
|
* Limited to range of timestamps.
|
||||||
*
|
*
|
||||||
* @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
|
* @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
|
||||||
* @param string $format (optional) Parsed with sprintf()
|
* @param string $format (optional) Parsed with sprintf()
|
||||||
|
* @param bool $compare_time Compare date (false) or date and time (true). "true" is default.
|
||||||
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
|
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
|
||||||
*
|
*
|
||||||
* @return string with relative date
|
* @return string with relative date
|
||||||
*/
|
*/
|
||||||
public static function getRelativeDate(string $posted_date = null, string $format = null): string
|
public static function getRelativeDate(string $posted_date = null, string $format = null, bool $compare_time = true): string
|
||||||
{
|
{
|
||||||
if (empty($posted_date) || $posted_date <= DBA::NULL_DATETIME) {
|
if (empty($posted_date) || $posted_date <= DBA::NULL_DATETIME) {
|
||||||
return DI::l10n()->t('never');
|
return DI::l10n()->t('never');
|
||||||
|
@ -324,11 +325,18 @@ class Temporal
|
||||||
return DI::l10n()->t('never');
|
return DI::l10n()->t('never');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
if (!$compare_time) {
|
||||||
|
$now = mktime(0, 0, 0, date('m', $now), date('d', $now), date('Y', $now));
|
||||||
|
$abs = mktime(0, 0, 0, date('m', $abs), date('d', $abs), date('Y', $abs));
|
||||||
|
}
|
||||||
|
|
||||||
$isfuture = false;
|
$isfuture = false;
|
||||||
$etime = time() - $abs;
|
$etime = $now - $abs;
|
||||||
|
|
||||||
if ($etime < 1 && $etime >= 0) {
|
if ($etime < 1 && $etime >= 0) {
|
||||||
return DI::l10n()->t('less than a second ago');
|
return $compare_time ? DI::l10n()->t('less than a second ago') : DI::l10n()->t('today');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($etime < 0){
|
if ($etime < 0){
|
||||||
|
|
Loading…
Reference in a new issue