Use generic string for seconds ago when needed
This commit is contained in:
parent
18a054747a
commit
caff432c0b
3 changed files with 12 additions and 9 deletions
|
@ -12,6 +12,7 @@ type State = {
|
|||
type Props = {
|
||||
clock24h?: boolean,
|
||||
date?: any,
|
||||
genericSeconds?: boolean,
|
||||
minUpdateDeltaMs?: number,
|
||||
showFutureDate?: boolean,
|
||||
timeAgo?: boolean,
|
||||
|
@ -59,18 +60,15 @@ class DateTime extends React.Component<Props, State> {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { clock24h, date, showFutureDate, timeAgo, type } = this.props;
|
||||
const { clock24h, date, genericSeconds, showFutureDate, timeAgo, type } = this.props;
|
||||
|
||||
const clockFormat = clock24h ? 'HH:mm' : 'hh:mm A';
|
||||
|
||||
return (
|
||||
<span
|
||||
className="date_time"
|
||||
title={timeAgo && moment(date).format(`MMMM Do, YYYY ${clockFormat}`)}
|
||||
>
|
||||
<span className="date_time" title={timeAgo && moment(date).format(`MMMM Do, YYYY ${clockFormat}`)}>
|
||||
{date
|
||||
? timeAgo
|
||||
? getTimeAgoStr(date, showFutureDate)
|
||||
? getTimeAgoStr(date, showFutureDate, genericSeconds)
|
||||
: moment(date).format(type === 'date' ? 'MMMM Do, YYYY' : clockFormat)
|
||||
: '...'}
|
||||
</span>
|
||||
|
|
|
@ -108,7 +108,7 @@ function LivestreamComment(props: Props) {
|
|||
)}
|
||||
|
||||
{/* Use key to force timestamp update */}
|
||||
<DateTime date={timePosted} timeAgo key={forceUpdate} />
|
||||
<DateTime date={timePosted} timeAgo key={forceUpdate} genericSeconds />
|
||||
|
||||
{comment.removed ? (
|
||||
<div className="livestream-comment__text">
|
||||
|
|
|
@ -36,10 +36,11 @@ export function hmsToSeconds(str: string) {
|
|||
|
||||
// Only intended use of future dates is for claims, in case of scheduled
|
||||
// publishes or livestreams, used in util/formatAriaLabel
|
||||
export function getTimeAgoStr(date: any, showFutureDate?: boolean) {
|
||||
export function getTimeAgoStr(date: any, showFutureDate?: boolean, genericSecondsString?: boolean) {
|
||||
const suffixList = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
|
||||
let duration = 0;
|
||||
let suffix = '';
|
||||
let str = '';
|
||||
|
||||
suffixList.some((s) => {
|
||||
// moment() is very liberal with it's rounding.
|
||||
|
@ -56,7 +57,11 @@ export function getTimeAgoStr(date: any, showFutureDate?: boolean) {
|
|||
// Strip off the ending 's' for the singular suffix
|
||||
if (duration === 1) suffix = suffix.replace(/s$/g, '');
|
||||
|
||||
const str = duration <= 0 ? 'Just now' : '%duration% ' + suffix + ' ago';
|
||||
if (duration <= 0) {
|
||||
str = 'Just now';
|
||||
} else {
|
||||
str = suffix === 'seconds' && genericSecondsString ? 'A few seconds ago' : '%duration% ' + suffix + ' ago';
|
||||
}
|
||||
|
||||
return __(str, { duration });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue