summaryrefslogtreecommitdiffstats
path: root/webapp/components/time_since.jsx
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-03-16 18:13:16 -0700
committer=Corey Hulen <corey@hulen.com>2016-03-16 18:13:16 -0700
commitb9d5b4e5dcc1585397f1e1d2e53c5f040ee76220 (patch)
tree85d2c293aa3456182a754fefe6646162b516eb6c /webapp/components/time_since.jsx
parente101b2cf7c172d1c4ff20e0df63917b5b8f923ed (diff)
parentcba59d4eb6ef0f65304bc72339c676ebfd653e2b (diff)
downloadchat-b9d5b4e5dcc1585397f1e1d2e53c5f040ee76220.tar.gz
chat-b9d5b4e5dcc1585397f1e1d2e53c5f040ee76220.tar.bz2
chat-b9d5b4e5dcc1585397f1e1d2e53c5f040ee76220.zip
merging files
Diffstat (limited to 'webapp/components/time_since.jsx')
-rw-r--r--webapp/components/time_since.jsx67
1 files changed, 67 insertions, 0 deletions
diff --git a/webapp/components/time_since.jsx b/webapp/components/time_since.jsx
new file mode 100644
index 000000000..02b0174ae
--- /dev/null
+++ b/webapp/components/time_since.jsx
@@ -0,0 +1,67 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import Constants from 'utils/constants.jsx';
+import * as Utils from 'utils/utils.jsx';
+
+import {FormattedRelative, FormattedDate} from 'react-intl';
+
+import {Tooltip, OverlayTrigger} from 'react-bootstrap';
+
+import React from 'react';
+
+export default class TimeSince extends React.Component {
+ componentDidMount() {
+ this.intervalId = setInterval(() => {
+ this.forceUpdate();
+ }, Constants.TIME_SINCE_UPDATE_INTERVAL);
+ }
+ componentWillUnmount() {
+ clearInterval(this.intervalId);
+ }
+ render() {
+ if (this.props.sameUser) {
+ return (
+ <time className='post__time'>
+ {Utils.displayTimeFormatted(this.props.eventTime)}
+ </time>
+ );
+ }
+
+ const tooltip = (
+ <Tooltip id={'time-since-tooltip-' + this.props.eventTime}>
+ <FormattedDate
+ value={this.props.eventTime}
+ month='long'
+ day='numeric'
+ year='numeric'
+ hour12={true}
+ hour='numeric'
+ minute='2-digit'
+ />
+ </Tooltip>
+ );
+
+ return (
+ <OverlayTrigger
+ delayShow={Constants.OVERLAY_TIME_DELAY}
+ placement='top'
+ overlay={tooltip}
+ >
+ <time className='post__time'>
+ <FormattedRelative value={this.props.eventTime}/>
+ </time>
+ </OverlayTrigger>
+ );
+ }
+}
+
+TimeSince.defaultProps = {
+ eventTime: 0,
+ sameUser: false
+};
+
+TimeSince.propTypes = {
+ eventTime: React.PropTypes.number.isRequired,
+ sameUser: React.PropTypes.bool
+};