Fix date formatting for cases when no navigator language is not set

This commit is contained in:
Thomas Nordquist
2019-03-25 19:48:07 +01:00
parent 62cbf6547e
commit 89d363fbaa

View File

@@ -7,16 +7,16 @@ interface Props {
class DateFormatter extends React.Component<Props, {}> { class DateFormatter extends React.Component<Props, {}> {
public render() { public render() {
const momentObject = this.localizedMoment() const locale = window.navigator.language
return <span>{momentObject.format('L')} {momentObject.format('LTS')}</span> return <span>{locale ? this.localizedDate(locale) : this.legacyDate()}</span>
} }
private getLocale() { private legacyDate() {
return window.navigator.language return `${this.props.date.toLocaleDateString()} ${this.props.date.toLocaleTimeString()}`
} }
private localizedMoment() { private localizedDate(locale: string) {
return moment(this.props.date).locale(this.getLocale()) return moment(this.props.date).locale(locale).format('L LTS')
} }
} }