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_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>
); );
} }

View file

@ -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" }}>&#9899;</span> <span style={{ margin: "10px" }}>&#9899;</span>
<span class="meta"> <span>
Published on <DateTime block={height} /> Published on <DateTime block={height} show="date" />
</span> </span>
</div> </div>
</div> </div>