Make date distance format use correct verbiage

This commit is contained in:
SleeplessOne1917 2023-06-23 10:33:07 -04:00 committed by Jay Sitter
parent 40c236eb9d
commit 543de49622
4 changed files with 21 additions and 13 deletions

View file

@ -1,6 +1,5 @@
import { capitalizeFirstLetter } from "@utils/helpers"; import { capitalizeFirstLetter, formatPastDate } from "@utils/helpers";
import format from "date-fns/format"; import format from "date-fns/format";
import formatDistanceToNow from "date-fns/formatDistanceToNow";
import parseISO from "date-fns/parseISO"; import parseISO from "date-fns/parseISO";
import { Component } from "inferno"; import { Component } from "inferno";
import { I18NextService } from "../../services"; import { I18NextService } from "../../services";
@ -43,7 +42,7 @@ export class MomentTime extends Component<MomentTimeProps, any> {
className="moment-time font-italics pointer unselectable" className="moment-time font-italics pointer unselectable"
> >
<Icon icon="edit-2" classes="icon-inline me-1" /> <Icon icon="edit-2" classes="icon-inline me-1" />
{formatDistanceToNow(parseISO(this.props.updated))} {formatPastDate(this.props.updated)}
</span> </span>
); );
} else { } else {
@ -53,7 +52,7 @@ export class MomentTime extends Component<MomentTimeProps, any> {
className="moment-time pointer unselectable" className="moment-time pointer unselectable"
data-tippy-content={momentFormat(published)} data-tippy-content={momentFormat(published)}
> >
{formatDistanceToNow(parseISO(published))} {formatPastDate(published)}
</span> </span>
); );
} }

View file

@ -7,6 +7,7 @@ import {
} from "@utils/app"; } from "@utils/app";
import { import {
debounce, debounce,
formatPastDate,
getIdFromString, getIdFromString,
getPageFromString, getPageFromString,
getQueryParams, getQueryParams,
@ -15,8 +16,6 @@ import {
import { amAdmin, amMod } from "@utils/roles"; import { amAdmin, amMod } from "@utils/roles";
import type { QueryParams } from "@utils/types"; import type { QueryParams } from "@utils/types";
import { Choice, RouteDataResponse } from "@utils/types"; import { Choice, RouteDataResponse } from "@utils/types";
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict";
import parseISO from "date-fns/parseISO";
import { NoOptionI18nKeys } from "i18next"; import { NoOptionI18nKeys } from "i18next";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess"; import { T } from "inferno-i18next-dess";
@ -119,10 +118,6 @@ function getActionFromString(action?: string): ModlogActionType {
return action !== undefined ? (action as ModlogActionType) : "All"; return action !== undefined ? (action as ModlogActionType) : "All";
} }
function getExpires(expires: string) {
return formatDistanceToNowStrict(parseISO(expires));
}
const getModlogActionMapper = const getModlogActionMapper =
( (
actionType: ModlogActionType, actionType: ModlogActionType,
@ -376,7 +371,7 @@ function renderModlogType({ type_, view }: ModlogType) {
)} )}
{expires && ( {expires && (
<span> <span>
<div>expires: {getExpires(expires)}</div> <div>expires: {formatPastDate(expires)}</div>
</span> </span>
)} )}
</> </>
@ -408,7 +403,7 @@ function renderModlogType({ type_, view }: ModlogType) {
)} )}
{expires && ( {expires && (
<span> <span>
<div>expires: {getExpires(expires)}</div> <div>expires: {formatPastDate(expires)}</div>
</span> </span>
)} )}
</> </>
@ -472,7 +467,7 @@ function renderModlogType({ type_, view }: ModlogType) {
)} )}
{expires && ( {expires && (
<span> <span>
<div>expires: {getExpires(expires)}</div> <div>expires: {formatPastDate(expires)}</div>
</span> </span>
)} )}
</> </>

View file

@ -0,0 +1,12 @@
import formatDistanceStrict from "date-fns/formatDistanceStrict";
import parseISO from "date-fns/parseISO";
export default function (dateString?: string) {
return formatDistanceStrict(
parseISO(dateString ?? Date.now().toString()),
new Date(),
{
addSuffix: true,
}
);
}

View file

@ -1,6 +1,7 @@
import capitalizeFirstLetter from "./capitalize-first-letter"; import capitalizeFirstLetter from "./capitalize-first-letter";
import debounce from "./debounce"; import debounce from "./debounce";
import editListImmutable from "./edit-list-immutable"; import editListImmutable from "./edit-list-immutable";
import formatPastDate from "./format-past-date";
import futureDaysToUnixTime from "./future-days-to-unix-time"; import futureDaysToUnixTime from "./future-days-to-unix-time";
import getIdFromString from "./get-id-from-string"; import getIdFromString from "./get-id-from-string";
import getPageFromString from "./get-page-from-string"; import getPageFromString from "./get-page-from-string";
@ -26,6 +27,7 @@ export {
capitalizeFirstLetter, capitalizeFirstLetter,
debounce, debounce,
editListImmutable, editListImmutable,
formatPastDate,
futureDaysToUnixTime, futureDaysToUnixTime,
getIdFromString, getIdFromString,
getPageFromString, getPageFromString,