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 = {
|
type Props = {
|
||||||
clock24h?: boolean,
|
clock24h?: boolean,
|
||||||
date?: any,
|
date?: any,
|
||||||
|
genericSeconds?: boolean,
|
||||||
minUpdateDeltaMs?: number,
|
minUpdateDeltaMs?: number,
|
||||||
showFutureDate?: boolean,
|
showFutureDate?: boolean,
|
||||||
timeAgo?: boolean,
|
timeAgo?: boolean,
|
||||||
|
@ -59,18 +60,15 @@ class DateTime extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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';
|
const clockFormat = clock24h ? 'HH:mm' : 'hh:mm A';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span className="date_time" title={timeAgo && moment(date).format(`MMMM Do, YYYY ${clockFormat}`)}>
|
||||||
className="date_time"
|
|
||||||
title={timeAgo && moment(date).format(`MMMM Do, YYYY ${clockFormat}`)}
|
|
||||||
>
|
|
||||||
{date
|
{date
|
||||||
? timeAgo
|
? timeAgo
|
||||||
? getTimeAgoStr(date, showFutureDate)
|
? getTimeAgoStr(date, showFutureDate, genericSeconds)
|
||||||
: moment(date).format(type === 'date' ? 'MMMM Do, YYYY' : clockFormat)
|
: moment(date).format(type === 'date' ? 'MMMM Do, YYYY' : clockFormat)
|
||||||
: '...'}
|
: '...'}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -108,7 +108,7 @@ function LivestreamComment(props: Props) {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Use key to force timestamp update */}
|
{/* Use key to force timestamp update */}
|
||||||
<DateTime date={timePosted} timeAgo key={forceUpdate} />
|
<DateTime date={timePosted} timeAgo key={forceUpdate} genericSeconds />
|
||||||
|
|
||||||
{comment.removed ? (
|
{comment.removed ? (
|
||||||
<div className="livestream-comment__text">
|
<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
|
// Only intended use of future dates is for claims, in case of scheduled
|
||||||
// publishes or livestreams, used in util/formatAriaLabel
|
// 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'];
|
const suffixList = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
let suffix = '';
|
let suffix = '';
|
||||||
|
let str = '';
|
||||||
|
|
||||||
suffixList.some((s) => {
|
suffixList.some((s) => {
|
||||||
// moment() is very liberal with it's rounding.
|
// 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
|
// Strip off the ending 's' for the singular suffix
|
||||||
if (duration === 1) suffix = suffix.replace(/s$/g, '');
|
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 });
|
return __(str, { duration });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue