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