mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 14:21:13 +00:00
Make date distance format use correct verbiage
This commit is contained in:
parent
5d664656a2
commit
8f9b231487
4 changed files with 21 additions and 13 deletions
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
12
src/shared/utils/helpers/format-past-date.ts
Normal file
12
src/shared/utils/helpers/format-past-date.ts
Normal 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,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue