1 import { capitalizeFirstLetter } from "@utils/helpers";
2 import format from "date-fns/format";
3 import formatDistanceToNow from "date-fns/formatDistanceToNow";
4 import parseISO from "date-fns/parseISO";
5 import { Component } from "inferno";
6 import { I18NextService } from "../../services";
7 import { Icon } from "./icon";
9 interface MomentTimeProps {
13 ignoreUpdated?: boolean;
16 function momentFormat(input: string) {
17 return format(parseISO(input), "PPPPpppp");
20 export class MomentTime extends Component<MomentTimeProps, any> {
21 constructor(props: any, context: any) {
22 super(props, context);
25 createdAndModifiedTimes() {
26 const updated = this.props.updated;
27 let line = `${capitalizeFirstLetter(
28 I18NextService.i18n.t("created")
29 )}: ${momentFormat(this.props.published)}`;
31 line += `\n\n\n${capitalizeFirstLetter(
32 I18NextService.i18n.t("modified")
33 )} ${momentFormat(updated)}`;
39 if (!this.props.ignoreUpdated && this.props.updated) {
42 data-tippy-content={this.createdAndModifiedTimes()}
43 className="moment-time font-italics pointer unselectable"
45 <Icon icon="edit-2" classes="icon-inline me-1" />
46 {formatDistanceToNow(parseISO(this.props.updated))}
50 const published = this.props.published;
53 className="moment-time pointer unselectable"
54 data-tippy-content={momentFormat(published)}
56 {formatDistanceToNow(parseISO(published))}