Dates changed to relative form (except logs)

This commit is contained in:
Marcin Kurczewski 2014-02-16 13:10:29 +01:00
parent e36498f709
commit 7a5d97e153
6 changed files with 75 additions and 16 deletions

View file

@ -22,11 +22,8 @@
.comment {
clear: left;
}
.comment .date:before {
content: ' on ';
margin: 0 0.2em;
}
.comment .date {
margin: 0 0.2em 0 0.75em;
color: silver;
}

View file

@ -284,4 +284,48 @@ class TextHelper
return $html;
}
public static function formatDate($date, $plain = true)
{
if (!$date)
return 'Unknown';
if ($plain)
return date('Y-m-d H:i:s', $date);
$now = time();
$diff = abs($now - $date);
$future = $now < $date;
$mul = 60;
if ($diff < $mul)
return $future ? 'in a few seconds' : 'just now';
if ($diff < $mul * 2)
return $future ? 'in a minute' : 'a minute ago';
$prevMul = $mul; $mul *= 60;
if ($diff < $mul)
return $future ? 'in ' . round($diff / $prevMul) . ' minutes' : round($diff / $prevMul) . ' minutes ago';
if ($diff < $mul * 2)
return $future ? 'in an hour' : 'an hour ago';
$prevMul = $mul; $mul *= 24;
if ($diff < $mul)
return $future ? 'in ' . round($diff / $prevMul) . ' hours' : round($diff / $prevMul) . ' hours ago';
if ($diff < $mul * 2)
return $future ? 'tomorrow' : 'yesterday';
$prevMul = $mul; $mul *= 30.42;
if ($diff < $mul)
return $future ? 'in ' . round($diff / $prevMul) . ' days' : round($diff / $prevMul) . ' days ago';
if ($diff < $mul * 2)
return $future ? 'in a month' : 'a month ago';
$prevMul = $mul; $mul *= 12;
if ($diff < $mul)
return $future ? 'in ' . round($diff / $prevMul) . ' months' : round($diff / $prevMul) . ' months ago';
if ($diff < $mul * 2)
return $future ? 'in a year' : 'a year ago';
return $future ? 'in ' . round($diff / $mul) . ' years' : round($diff / $prevMul) . ' years ago';
}
}

View file

@ -28,8 +28,8 @@ LayoutHelper::addScript('comment-edit.js');
<?php endif ?>
</span>
<span class="date">
<?php echo date('Y-m-d H:i', $this->context->comment->commentDate) ?>
<span class="date" title="<?php echo TextHelper::formatDate($this->context->comment->commentDate, true) ?>">
<?php echo TextHelper::formatDate($this->context->comment->commentDate, false) ?>
</span>
<?php if (PrivilegesHelper::confirm(Privilege::EditComment, PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>

View file

@ -117,9 +117,9 @@ LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
</div>
<div class="key-value date">
<span class="key">Date:</span>
<span class="value" title="<?php echo $val = date('Y-m-d H:i', $this->context->transport->post->uploadDate) ?>">
<?php echo $val ?>
<span class="key">Uploaded:</span>
<span class="value" title="<?php echo TextHelper::formatDate($this->context->transport->post->uploadDate, true) ?>">
<?php echo TextHelper::formatDate($this->context->transport->post->uploadDate, false) ?>
</span>
</div>

View file

@ -50,9 +50,17 @@ if ($this->context->user->hasEnabledEndlessScrolling())
</a>
</h1>
<div class="date-registered">Registered: <?php echo date('Y-m-d H:i', $user->joinDate) ?></div>
<div class="fav-count">Favorite count: <?php echo $user->getFavoriteCount() ?></div>
<div class="post-count">Post count: <?php echo $user->getPostCount() ?></div>
<div class="date-registered" title="<?php echo TextHelper::formatDate($user->joinDate, true) ?>">
Registered: <?php echo TextHelper::formatDate($user->joinDate, false) ?>
</div>
<div class="post-count">
Uploaded: <?php echo TextHelper::useDecimalUnits($user->getPostCount()) ?>
</div>
<div class="fav-count">
Favorites: <?php echo TextHelper::useDecimalUnits($user->getFavoriteCount()) ?>
</div>
</div>
</div>
<?php endforeach ?>

View file

@ -16,23 +16,33 @@ LayoutHelper::addStylesheet('user-view.css');
<div class="key-value join-date">
<span class="key">Joined:</span>
<span class="value" title="<?php echo $val = date('Y-m-d', $this->context->transport->user->joinDate) ?>"><?php echo $val ?></span>
<span class="value" title="<?php echo TextHelper::formatDate($this->context->transport->user->joinDate, true) ?>">
<?php echo TextHelper::formatDate($this->context->transport->user->joinDate, false) ?>
</span>
</div>
<div class="key-value last-login">
<span class="key">Last login:</span>
<span class="value" title="<?php echo $val = $this->context->transport->user->lastLoginDate ? date('Y-m-d', $this->context->transport->user->lastLoginDate) : 'Unknown' ?>"><?php echo $val ?></span>
<span class="value" title="<?php echo TextHelper::formatDate($this->context->transport->user->lastLoginDate, true) ?>">
<?php echo TextHelper::formatDate($this->context->transport->user->lastLoginDate, false) ?>
</span>
</div>
<div class="key-value access-rank">
<span class="key">Access rank:</span>
<span class="value" title="<?php echo $val = TextHelper::camelCaseToHumanCase(AccessRank::toString($this->context->transport->user->accessRank)) ?>"><?php echo $val ?></span>
<span class="value" title="<?php echo $val = TextHelper::camelCaseToHumanCase(AccessRank::toString($this->context->transport->user->accessRank)) ?>">
<?php echo $val ?>
</span>
</div>
<?php if (PrivilegesHelper::confirm(Privilege::ViewUserEmail, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<div class="key-value email">
<span class="key">E-mail:</span>
<span class="value" title="<?php echo $val = ($this->context->transport->user->emailUnconfirmed ? '(unconfirmed) ' . $this->context->transport->user->emailUnconfirmed : $this->context->transport->user->emailConfirmed ?: 'none specified') ?>"><?php echo $val ?></span>
<span class="value" title="<?php echo $val = ($this->context->transport->user->emailUnconfirmed
? '(unconfirmed) ' . $this->context->transport->user->emailUnconfirmed
: $this->context->transport->user->emailConfirmed ?: 'none specified') ?>">
<?php echo $val ?>
</span>
<br>(only you and staff can see this)
</div>
<?php endif ?>