better format for dateTime component
This commit is contained in:
parent
e801f77fd9
commit
62053e6b36
2 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,14 @@ class DateTime extends React.PureComponent {
|
||||||
static SHOW_TIME = "time";
|
static SHOW_TIME = "time";
|
||||||
static SHOW_BOTH = "both";
|
static SHOW_BOTH = "both";
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
formatOptions: {
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.refreshDate(this.props);
|
this.refreshDate(this.props);
|
||||||
}
|
}
|
||||||
|
@ -23,16 +31,18 @@ class DateTime extends React.PureComponent {
|
||||||
render() {
|
render() {
|
||||||
const { date, formatOptions } = this.props;
|
const { date, formatOptions } = this.props;
|
||||||
const show = this.props.show || DateTime.SHOW_BOTH;
|
const show = this.props.show || DateTime.SHOW_BOTH;
|
||||||
|
const locale = app.i18n.getLocale();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{date &&
|
{date &&
|
||||||
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_DATE) &&
|
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_DATE) &&
|
||||||
date.toLocaleDateString()}
|
date.toLocaleDateString([locale, "en-US"], formatOptions)}
|
||||||
{show == DateTime.SHOW_BOTH && " "}
|
{show == DateTime.SHOW_BOTH && " "}
|
||||||
{date &&
|
{date &&
|
||||||
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_TIME) &&
|
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_TIME) &&
|
||||||
date.toLocaleTimeString()}
|
date.toLocaleTimeString()}
|
||||||
|
{!date && "..."}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,9 @@ class FilePage extends React.PureComponent {
|
||||||
<h1>{title}</h1>
|
<h1>{title}</h1>
|
||||||
<div className="card__subtitle">
|
<div className="card__subtitle">
|
||||||
<UriIndicator uri={uri} link={true} />
|
<UriIndicator uri={uri} link={true} />
|
||||||
<span class="meta" style={{ margin: "10px" }}>⚫</span>
|
<span style={{ margin: "10px" }}>⚫</span>
|
||||||
<span class="meta">
|
<span>
|
||||||
Published on <DateTime block={height} />
|
Published on <DateTime block={height} show="date" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue