]> Untitled Git - lemmy.git/blob - ui/src/components/moment-time.tsx
Localization testing mostly done.
[lemmy.git] / ui / src / components / moment-time.tsx
1 import { Component } from 'inferno';
2 import * as moment from 'moment';
3 import 'moment/locale/de.js';
4 import { getLanguage } from '../utils';
5 import { i18n } from '../i18next';
6
7 interface MomentTimeProps {
8   data: {
9     published?: string;
10     when_?: string;
11     updated?: string;
12   }
13 }
14
15 export class MomentTime extends Component<MomentTimeProps, any> {
16
17   constructor(props: any, context: any) {
18     super(props, context);
19     // console.log(moment.locales());
20     moment.locale(getLanguage());
21   }
22
23   render() {
24     if (this.props.data.updated) {
25       return (
26         <span title={this.props.data.updated} className="font-italics">{i18n.t('modified')} {moment.utc(this.props.data.updated).fromNow()}</span>
27       )
28     } else {
29       let str = this.props.data.published || this.props.data.when_;
30       return (
31         <span title={str}>{moment.utc(str).fromNow()}</span>
32       )
33     }
34   }
35 }