mirror of
https://github.com/wassname/talk.git
synced 2026-08-09 12:30:42 +08:00
36 lines
854 B
JavaScript
36 lines
854 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { timeago } from 'coral-framework/services/i18n';
|
|
|
|
class TimeAgo extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = { timeago: true };
|
|
}
|
|
toggleDate = () => this.setState({ timeago: !this.state.timeago });
|
|
render() {
|
|
var displayTime = this.state.timeago
|
|
? timeago(this.props.datetime)
|
|
: new Date(this.props.datetime).toLocaleString();
|
|
|
|
var titleDate = !this.state.timeago
|
|
? timeago(this.props.datetime)
|
|
: new Date(this.props.datetime).toLocaleString();
|
|
return (
|
|
<span
|
|
onClick={this.toggleDate}
|
|
style={{ cursor: 'pointer' }}
|
|
title={titleDate}
|
|
>
|
|
{displayTime}
|
|
</span>
|
|
);
|
|
}
|
|
}
|
|
|
|
TimeAgo.propTypes = {
|
|
datetime: PropTypes.string,
|
|
};
|
|
|
|
export default TimeAgo;
|