0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added in a explicit time as a title tooltip for relative dates in comments

- Uses the title attribute to pop up the default tooltip
- No helper function introduced to generate explicit date

refs https://github.com/TryGhost/Team/issues/1741
This commit is contained in:
James Morris 2022-08-03 17:42:20 +01:00
parent 9b402625ca
commit a2597e5584
2 changed files with 14 additions and 2 deletions

View file

@ -7,7 +7,7 @@ import More from './More';
import Form from './Form';
import Replies from './Replies';
import AppContext from '../AppContext';
import {formatRelativeTime} from '../utils/helpers';
import {formatRelativeTime, formatExplicitTime} from '../utils/helpers';
function EditedInfo({comment}) {
if (!comment.edited_at) {
@ -93,7 +93,7 @@ const Comment = ({updateIsEditing = null, isEditing, ...props}) => {
<h4 className="text-[17px] font-sans font-bold tracking-tight dark:text-[rgba(255,255,255,0.85)]">{!comment.member ? 'Deleted member' : (comment.member.name ? comment.member.name : 'Anonymous')}</h4>
<div className="flex items-baseline font-sans text-[14px] tracking-tight text-neutral-400 dark:text-[rgba(255,255,255,0.5)]">
{comment.member.bio && <div>{comment.member.bio}<span className="mx-[0.3em]">·</span></div>}
<div>{formatRelativeTime(comment.created_at)}</div>
<div title={formatExplicitTime(comment.created_at)}>{formatRelativeTime(comment.created_at)}</div>
<EditedInfo comment={comment} />
</div>
</div>}

View file

@ -88,6 +88,18 @@ export function formatRelativeTime(dateString) {
return `${Math.floor(diff)} weeks ago`;
}
export function formatExplicitTime(dateString) {
const date = new Date(dateString);
let day = date.toLocaleDateString('en-us', {day: '2-digit'}); // eg. 01
let month = date.toLocaleString('en-us', {month: 'short'}); // eg. Jan
let year = date.getFullYear(); // eg. 2022
let hour = (date.getHours() < 10 ? '0' : '') + date.getHours(); // eg. 02
let minute = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes(); // eg. 09
return `${day} ${month} ${year} ${hour}:${minute}`;
}
export function getInitials(name) {
if (!name) {
return '';