better format for dateTime component

This commit is contained in:
btzr-io 2017-10-08 14:43:56 -06:00
parent e801f77fd9
commit 62053e6b36
2 changed files with 14 additions and 4 deletions

View file

@ -5,6 +5,14 @@ class DateTime extends React.PureComponent {
static SHOW_TIME = "time";
static SHOW_BOTH = "both";
static defaultProps = {
formatOptions: {
month: "long",
day: "numeric",
year: "numeric",
},
};
componentWillMount() {
this.refreshDate(this.props);
}
@ -23,16 +31,18 @@ class DateTime extends React.PureComponent {
render() {
const { date, formatOptions } = this.props;
const show = this.props.show || DateTime.SHOW_BOTH;
const locale = app.i18n.getLocale();
return (
<span>
{date &&
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_DATE) &&
date.toLocaleDateString()}
date.toLocaleDateString([locale, "en-US"], formatOptions)}
{show == DateTime.SHOW_BOTH && " "}
{date &&
(show == DateTime.SHOW_BOTH || show === DateTime.SHOW_TIME) &&
date.toLocaleTimeString()}
{!date && "..."}
</span>
);
}

View file

@ -87,9 +87,9 @@ class FilePage extends React.PureComponent {
<h1>{title}</h1>
<div className="card__subtitle">
<UriIndicator uri={uri} link={true} />
<span class="meta" style={{ margin: "10px" }}>&#9899;</span>
<span class="meta">
Published on <DateTime block={height} />
<span style={{ margin: "10px" }}>&#9899;</span>
<span>
Published on <DateTime block={height} show="date" />
</span>
</div>
</div>