From 22c024cc94e280545cf4901c6e8d7ed555d5b271 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 14 Jan 2018 18:33:58 +0000 Subject: [PATCH 1/3] Refactor DateSep, use new Dateutils.formatFullDateNoTime as it is not desired for it to include the time. Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/messages/DateSeparator.js | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/components/views/messages/DateSeparator.js b/src/components/views/messages/DateSeparator.js index 5d579e5d8..4dcac99da 100644 --- a/src/components/views/messages/DateSeparator.js +++ b/src/components/views/messages/DateSeparator.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +16,9 @@ limitations under the License. */ import React from 'react'; +import PropTypes from 'prop-types'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; -import {formatFullDate} from 'matrix-react-sdk/lib/DateUtils'; +import {formatFullDateNoTime} from 'matrix-react-sdk/lib/DateUtils'; function getdaysArray() { return [ @@ -30,30 +32,30 @@ function getdaysArray() { ]; } -module.exports = React.createClass({ - displayName: 'DateSeparator', - render: function() { - var date = new Date(this.props.ts); - var today = new Date(); - var yesterday = new Date(); - var days = getdaysArray(); - yesterday.setDate(today.getDate() - 1); - var label; - if (date.toDateString() === today.toDateString()) { - label = _t('Today'); - } - else if (date.toDateString() === yesterday.toDateString()) { - label = _t('Yesterday'); - } - else if (today.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { - label = days[date.getDay()]; - } - else { - label = formatFullDate(date, this.props.showTwelveHour); - } +export class DateSeparator extends React.Component { + static propTypes = { + ts: PropTypes.number.isRequired, + }; - return ( -

{ label }

- ); + getLabel() { + const date = new Date(this.props.ts); + const today = new Date(); + const yesterday = new Date(); + const days = getdaysArray(); + yesterday.setDate(today.getDate() - 1); + + if (date.toDateString() === today.toDateString()) { + return _t('Today'); + } else if (date.toDateString() === yesterday.toDateString()) { + return _t('Yesterday'); + } else if (today.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { + return days[date.getDay()]; + } else { + return formatFullDateNoTime(date); + } } -}); + + render() { + return

{ this.getLabel() }

; + } +} From b65fdf6ab0572b5ebe26636897736fab9e4d7172 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 14 Jan 2018 18:35:53 +0000 Subject: [PATCH 2/3] refactor MessageTimestamp, as it was missing a PropTypes def for ts Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/messages/MessageTimestamp.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/views/messages/MessageTimestamp.js b/src/components/views/messages/MessageTimestamp.js index 3d972e4c1..eafa25daf 100644 --- a/src/components/views/messages/MessageTimestamp.js +++ b/src/components/views/messages/MessageTimestamp.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,24 +15,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -'use strict'; - import React from 'react'; +import PropTypes from 'prop-types'; import {formatFullDate, formatTime} from 'matrix-react-sdk/lib/DateUtils'; -module.exports = React.createClass({ - displayName: 'MessageTimestamp', +export class MessageTimestamp extends React.Component { + static propTypes = { + ts: PropTypes.number.isRequired, + showTwelveHour: PropTypes.bool, + }; - propTypes: { - showTwelveHour: React.PropTypes.bool, - }, - - render: function() { + render() { const date = new Date(this.props.ts); return ( - + { formatTime(date, this.props.showTwelveHour) } ); - }, -}); + } +} From f97395f40fc95e011f6d43540a8eae5a724ab1c3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 14 Jan 2018 18:41:44 +0000 Subject: [PATCH 3/3] change exports to default to retain compatibility with existing imports Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/messages/DateSeparator.js | 2 +- src/components/views/messages/MessageTimestamp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/messages/DateSeparator.js b/src/components/views/messages/DateSeparator.js index 4dcac99da..2e081bc69 100644 --- a/src/components/views/messages/DateSeparator.js +++ b/src/components/views/messages/DateSeparator.js @@ -32,7 +32,7 @@ function getdaysArray() { ]; } -export class DateSeparator extends React.Component { +export default class DateSeparator extends React.Component { static propTypes = { ts: PropTypes.number.isRequired, }; diff --git a/src/components/views/messages/MessageTimestamp.js b/src/components/views/messages/MessageTimestamp.js index eafa25daf..6d4330670 100644 --- a/src/components/views/messages/MessageTimestamp.js +++ b/src/components/views/messages/MessageTimestamp.js @@ -19,7 +19,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import {formatFullDate, formatTime} from 'matrix-react-sdk/lib/DateUtils'; -export class MessageTimestamp extends React.Component { +export default class MessageTimestamp extends React.Component { static propTypes = { ts: PropTypes.number.isRequired, showTwelveHour: PropTypes.bool,