Don't show seconds in ImageView

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-04-02 09:25:21 +02:00
parent e79254e7bf
commit 80854ab6bb
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
3 changed files with 16 additions and 11 deletions

View File

@ -97,7 +97,7 @@ export function formatFullDateNoTime(date: Date): string {
}); });
} }
export function formatFullDate(date: Date, showTwelveHour = false): string { export function formatFullDate(date: Date, showTwelveHour = false, showSeconds = true): string {
const days = getDaysArray(); const days = getDaysArray();
const months = getMonthsArray(); const months = getMonthsArray();
return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s', { return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s', {
@ -105,7 +105,7 @@ export function formatFullDate(date: Date, showTwelveHour = false): string {
monthName: months[date.getMonth()], monthName: months[date.getMonth()],
day: date.getDate(), day: date.getDate(),
fullYear: date.getFullYear(), fullYear: date.getFullYear(),
time: formatFullTime(date, showTwelveHour), time: showSeconds ? formatFullTime(date, showTwelveHour) : formatTime(date, showTwelveHour),
}); });
} }

View File

@ -275,11 +275,10 @@ export default class ImageView extends React.Component {
<a <a
href={permalink} href={permalink}
onClick={this.onPermalinkClicked} onClick={this.onPermalinkClicked}
aria-label={formatFullDate(new Date(this.props.mxEvent.getTs()), this.props.isTwelveHour)} aria-label={formatFullDate(new Date(this.props.mxEvent.getTs()), this.props.isTwelveHour, false)}
> >
<MessageTimestamp showFullDate={true} showTwelveHour={showTwelveHour} ts={mxEvent.getTs()} /> <MessageTimestamp showFullDate={true} showTwelveHour={showTwelveHour} ts={mxEvent.getTs()} showSeconds={false} />
</a> </a>
); );
const avatar = ( const avatar = (
<MemberAvatar <MemberAvatar

View File

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {formatFullDate, formatTime} from '../../../DateUtils'; import {formatFullDate, formatTime, formatFullTime} from '../../../DateUtils';
import {replaceableComponent} from "../../../utils/replaceableComponent"; import {replaceableComponent} from "../../../utils/replaceableComponent";
@replaceableComponent("views.messages.MessageTimestamp") @replaceableComponent("views.messages.MessageTimestamp")
@ -26,17 +26,23 @@ export default class MessageTimestamp extends React.Component {
ts: PropTypes.number.isRequired, ts: PropTypes.number.isRequired,
showTwelveHour: PropTypes.bool, showTwelveHour: PropTypes.bool,
showFullDate: PropTypes.bool, showFullDate: PropTypes.bool,
showSeconds: PropTypes.bool,
}; };
render() { render() {
const date = new Date(this.props.ts); const date = new Date(this.props.ts);
let timestamp;
if (this.props.showFullDate) {
timestamp = formatFullDate(date, this.props.showTwelveHour, this.props.showSeconds);
} else if (this.props.showSeconds) {
timestamp = formatFullTime(date, this.props.showTwelveHour);
} else {
timestamp = formatTime(date, this.props.showTwelveHour);
}
return ( return (
<span className="mx_MessageTimestamp" title={formatFullDate(date, this.props.showTwelveHour)} aria-hidden={true}> <span className="mx_MessageTimestamp" title={formatFullDate(date, this.props.showTwelveHour)} aria-hidden={true}>
{ {timestamp}
this.props.showFullDate ?
formatFullDate(date, this.props.showTwelveHour) :
formatTime(date, this.props.showTwelveHour)
}
</span> </span>
); );
} }