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_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>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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" }}>⚫</span>
|
||||
<span class="meta">
|
||||
Published on <DateTime block={height} />
|
||||
<span style={{ margin: "10px" }}>⚫</span>
|
||||
<span>
|
||||
Published on <DateTime block={height} show="date" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue