1 import { Option } from "@sniptt/monads";
2 import { Component } from "inferno";
3 import moment from "moment";
4 import { i18n } from "../../i18next";
5 import { capitalizeFirstLetter, getLanguages } from "../../utils";
6 import { Icon } from "./icon";
8 interface MomentTimeProps {
10 updated: Option<string>;
12 ignoreUpdated?: boolean;
15 export class MomentTime extends Component<MomentTimeProps, any> {
16 constructor(props: any, context: any) {
17 super(props, context);
19 let lang = getLanguages();
24 createdAndModifiedTimes() {
25 return `${capitalizeFirstLetter(i18n.t("created"))}: ${this.format(
28 this.props.updated.isSome() && capitalizeFirstLetter(i18n.t("modified"))
29 } ${this.format(this.props.updated.unwrap())}`;
33 if (!this.props.ignoreUpdated && this.props.updated.isSome()) {
36 data-tippy-content={this.createdAndModifiedTimes()}
37 className="font-italics pointer unselectable"
39 <Icon icon="edit-2" classes="icon-inline mr-1" />
40 {moment.utc(this.props.updated.unwrap()).fromNow(!this.props.showAgo)}
44 let published = this.props.published;
47 className="pointer unselectable"
48 data-tippy-content={this.format(published)}
50 {moment.utc(published).fromNow(!this.props.showAgo)}
56 format(input: string): string {
57 return moment.utc(input).local().format("LLLL");