1 import { capitalizeFirstLetter } from "@utils/helpers";
2 import { Component } from "inferno";
3 import moment from "moment";
4 import { I18NextService } from "../../services";
5 import { Icon } from "./icon";
7 interface MomentTimeProps {
11 ignoreUpdated?: boolean;
14 export class MomentTime extends Component<MomentTimeProps, any> {
15 constructor(props: any, context: any) {
16 super(props, context);
18 moment.locale([...I18NextService.i18n.languages]);
21 createdAndModifiedTimes() {
22 const updated = this.props.updated;
23 let line = `${capitalizeFirstLetter(
24 I18NextService.i18n.t("created")
25 )}: ${this.format(this.props.published)}`;
27 line += `\n\n\n${capitalizeFirstLetter(
28 I18NextService.i18n.t("modified")
29 )} ${this.format(updated)}`;
35 if (!this.props.ignoreUpdated && this.props.updated) {
38 data-tippy-content={this.createdAndModifiedTimes()}
39 className="moment-time font-italics pointer unselectable"
41 <Icon icon="edit-2" classes="icon-inline me-1" />
42 {moment.utc(this.props.updated).fromNow(!this.props.showAgo)}
46 const published = this.props.published;
49 className="moment-time pointer unselectable"
50 data-tippy-content={this.format(published)}
52 {moment.utc(published).fromNow(!this.props.showAgo)}
58 format(input: string): string {
59 return moment.utc(input).local().format("LLLL");