2018-09-03 16:17:36 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import moment from "moment";
|
|
|
|
|
import { translate } from "react-i18next";
|
2019-02-07 09:28:43 +01:00
|
|
|
import injectSheet from "react-jss";
|
|
|
|
|
|
2019-03-12 10:44:58 +01:00
|
|
|
// fix german locale
|
|
|
|
|
// https://momentjscom.readthedocs.io/en/latest/moment/00-use-it/07-browserify/
|
|
|
|
|
import "moment/locale/de";
|
|
|
|
|
|
2019-02-07 09:28:43 +01:00
|
|
|
const styles = {
|
|
|
|
|
date: {
|
|
|
|
|
borderBottom: "1px dotted rgba(219, 219, 219)",
|
|
|
|
|
cursor: "help"
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-09-03 16:17:36 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
date?: string,
|
|
|
|
|
|
|
|
|
|
// context props
|
2019-02-07 09:28:43 +01:00
|
|
|
classes: any,
|
2018-09-03 16:17:36 +02:00
|
|
|
i18n: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DateFromNow extends React.Component<Props> {
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-02-07 09:28:43 +01:00
|
|
|
const { i18n, date, classes } = this.props;
|
|
|
|
|
|
|
|
|
|
if (date) {
|
|
|
|
|
const dateWithLocale = moment(date).locale(i18n.language);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<time title={dateWithLocale.format()} className={classes.date}>
|
|
|
|
|
{dateWithLocale.fromNow()}
|
|
|
|
|
</time>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
|
2019-02-07 09:28:43 +01:00
|
|
|
return null;
|
2018-09-03 16:17:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 09:28:43 +01:00
|
|
|
export default injectSheet(styles)(translate()(DateFromNow));
|