mirror of https://github.com/vector-im/riot-web
Refactor DateUtils to ES6
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
9e2238e884
commit
e45fcf10c7
|
@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
import { _t } from './languageHandler';
|
||||
|
||||
function getDaysArray() {
|
||||
|
@ -59,18 +58,17 @@ function twelveHourTime(date) {
|
|||
return `${hours}:${minutes}${ampm}`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatDate: function(date, showTwelveHour=false) {
|
||||
export function formatDate(date, showTwelveHour=false) {
|
||||
const now = new Date();
|
||||
const days = getDaysArray();
|
||||
const months = getMonthsArray();
|
||||
if (date.toDateString() === now.toDateString()) {
|
||||
return this.formatTime(date, showTwelveHour);
|
||||
return formatTime(date, showTwelveHour);
|
||||
} else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
|
||||
// TODO: use standard date localize function provided in counterpart
|
||||
return _t('%(weekDayName)s %(time)s', {
|
||||
weekDayName: days[date.getDay()],
|
||||
time: this.formatTime(date, showTwelveHour),
|
||||
time: formatTime(date, showTwelveHour),
|
||||
});
|
||||
} else if (now.getFullYear() === date.getFullYear()) {
|
||||
// TODO: use standard date localize function provided in counterpart
|
||||
|
@ -78,13 +76,13 @@ module.exports = {
|
|||
weekDayName: days[date.getDay()],
|
||||
monthName: months[date.getMonth()],
|
||||
day: date.getDate(),
|
||||
time: this.formatTime(date, showTwelveHour),
|
||||
time: formatTime(date, showTwelveHour),
|
||||
});
|
||||
}
|
||||
return this.formatFullDate(date, showTwelveHour);
|
||||
},
|
||||
return formatFullDate(date, showTwelveHour);
|
||||
}
|
||||
|
||||
formatFullDate: function(date, showTwelveHour=false) {
|
||||
export function formatFullDate(date, showTwelveHour=false) {
|
||||
const days = getDaysArray();
|
||||
const months = getMonthsArray();
|
||||
return _t('%(weekDayName)s, %(monthName)s %(day)s %(fullYear)s %(time)s', {
|
||||
|
@ -92,14 +90,13 @@ module.exports = {
|
|||
monthName: months[date.getMonth()],
|
||||
day: date.getDate(),
|
||||
fullYear: date.getFullYear(),
|
||||
time: this.formatTime(date, showTwelveHour),
|
||||
time: formatTime(date, showTwelveHour),
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
formatTime: function(date, showTwelveHour=false) {
|
||||
export function formatTime(date, showTwelveHour=false) {
|
||||
if (showTwelveHour) {
|
||||
return twelveHourTime(date);
|
||||
}
|
||||
return pad(date.getHours()) + ':' + pad(date.getMinutes());
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ const Velociraptor = require('../../../Velociraptor');
|
|||
require('../../../VelocityBounce');
|
||||
import { _t } from '../../../languageHandler';
|
||||
|
||||
import DateUtils from '../../../DateUtils';
|
||||
import {formatDate} from '../../../DateUtils';
|
||||
|
||||
let bounce = false;
|
||||
try {
|
||||
|
@ -187,7 +187,7 @@ module.exports = React.createClass({
|
|||
if (this.props.timestamp) {
|
||||
title = _t(
|
||||
"Seen by %(userName)s at %(dateTime)s",
|
||||
{userName: this.props.member.userId, dateTime: DateUtils.formatDate(new Date(this.props.timestamp), this.props.showTwelveHour)},
|
||||
{userName: this.props.member.userId, dateTime: formatDate(new Date(this.props.timestamp), this.props.showTwelveHour)},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import PropTypes from 'prop-types';
|
|||
import sdk from '../../../index';
|
||||
import { _t } from '../../../languageHandler';
|
||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||
import DateUtils from '../../../DateUtils';
|
||||
import {formatDate} from '../../../DateUtils';
|
||||
|
||||
export default class DevicesPanelEntry extends React.Component {
|
||||
constructor(props, context) {
|
||||
|
@ -56,7 +56,7 @@ export default class DevicesPanelEntry extends React.Component {
|
|||
|
||||
let lastSeen = "";
|
||||
if (device.last_seen_ts) {
|
||||
const lastSeenDate = DateUtils.formatDate(new Date(device.last_seen_ts));
|
||||
const lastSeenDate = formatDate(new Date(device.last_seen_ts));
|
||||
lastSeen = device.last_seen_ip + " @ " +
|
||||
lastSeenDate.toLocaleString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue