2017-09-03 18:35:01 +02:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
class DateTime extends React.PureComponent {
|
2017-09-18 02:52:57 +02:00
|
|
|
static SHOW_DATE = "date";
|
|
|
|
static SHOW_TIME = "time";
|
|
|
|
static SHOW_BOTH = "both";
|
|
|
|
|
2017-09-03 18:35:01 +02:00
|
|
|
componentWillMount() {
|
|
|
|
this.refreshDate(this.props);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(props) {
|
|
|
|
this.refreshDate(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshDate(props) {
|
|
|
|
const { block, date, fetchBlock } = props;
|
|
|
|
if (block && date === undefined) {
|
|
|
|
fetchBlock(block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-18 02:52:57 +02:00
|
|
|
const { date, formatOptions } = this.props;
|
|
|
|
const show = this.props.show || DateTime.SHOW_BOTH;
|
2017-09-03 18:35:01 +02:00
|
|
|
|
2017-09-18 02:52:57 +02:00
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{date &&
|
|
|
|
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_DATE) &&
|
|
|
|
date.toLocaleDateString()}
|
|
|
|
{show == DateTime.SHOW_BOTH && " "}
|
|
|
|
{date &&
|
|
|
|
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_TIME) &&
|
|
|
|
date.toLocaleTimeString()}
|
|
|
|
</span>
|
|
|
|
);
|
2017-09-03 18:35:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DateTime;
|