Use 12h timestamps when enabled in RR

Fixes vector-im/riot-web#4393 
Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
turt2live 2017-06-22 08:53:58 -06:00
parent 042152aa66
commit a22f14e910
3 changed files with 8 additions and 4 deletions

View file

@ -60,7 +60,7 @@ function twelveHourTime(date) {
} }
module.exports = { module.exports = {
formatDate: function(date) { formatDate: function(date, showTwelveHour=false) {
var now = new Date(); var now = new Date();
const days = getDaysArray(); const days = getDaysArray();
const months = getMonthsArray(); const months = getMonthsArray();
@ -69,7 +69,7 @@ module.exports = {
} }
else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
// TODO: use standard date localize function provided in counterpart // TODO: use standard date localize function provided in counterpart
return _t('%(weekDayName)s %(time)s', {weekDayName: days[date.getDay()], time: this.formatTime(date)}); return _t('%(weekDayName)s %(time)s', {weekDayName: days[date.getDay()], time: this.formatTime(date, showTwelveHour)});
} }
else if (now.getFullYear() === date.getFullYear()) { else if (now.getFullYear() === date.getFullYear()) {
// TODO: use standard date localize function provided in counterpart // TODO: use standard date localize function provided in counterpart
@ -80,7 +80,7 @@ module.exports = {
time: this.formatTime(date), time: this.formatTime(date),
}); });
} }
return this.formatFullDate(date); return this.formatFullDate(date, showTwelveHour);
}, },
formatFullDate: function(date, showTwelveHour=false) { formatFullDate: function(date, showTwelveHour=false) {

View file

@ -336,6 +336,7 @@ module.exports = WithMatrixClient(React.createClass({
suppressAnimation={this._suppressReadReceiptAnimation} suppressAnimation={this._suppressReadReceiptAnimation}
onClick={this.toggleAllReadAvatars} onClick={this.toggleAllReadAvatars}
timestamp={receipt.ts} timestamp={receipt.ts}
showTwelveHour={this.props.isTwelveHour}
/> />
); );
} }

View file

@ -66,6 +66,9 @@ module.exports = React.createClass({
// Timestamp when the receipt was read // Timestamp when the receipt was read
timestamp: React.PropTypes.number, timestamp: React.PropTypes.number,
// True to show twelve hour format, false otherwise
showTwelveHour: React.PropTypes.bool,
}, },
getDefaultProps: function() { getDefaultProps: function() {
@ -172,7 +175,7 @@ module.exports = React.createClass({
if (this.props.timestamp) { if (this.props.timestamp) {
title = _t( title = _t(
"Seen by %(userName)s at %(dateTime)s", "Seen by %(userName)s at %(dateTime)s",
{userName: this.props.member.userId, dateTime: DateUtils.formatDate(new Date(this.props.timestamp))} {userName: this.props.member.userId, dateTime: DateUtils.formatDate(new Date(this.props.timestamp), this.props.showTwelveHour)}
); );
} }