Fix date formatting for cases when no navigator language is not set
This commit is contained in:
@@ -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')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user