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