diff --git a/public/locales/en.json b/public/locales/en.json index 157736c..8c0991a 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -290,6 +290,8 @@ "addressCopyButtons": "Show copy buttons next to all addresses", "nameCopyButtons": "Show copy buttons next to all names", "blockHashCopyButtons": "Show copy buttons next to all block hashes", + "showRelativeDates": "Show relative dates instead of absolute ones if recent", + "showRelativeDatesDescription": "Everywhere on the site, if a date is less than 7 days ago, it will show as a relative date instead.", "subMenuDebug": "Debug settings", "advancedWalletFormats": "Advanced wallet formats", diff --git a/src/components/DateTime.tsx b/src/components/DateTime.tsx index b839843..291604b 100644 --- a/src/components/DateTime.tsx +++ b/src/components/DateTime.tsx @@ -5,6 +5,8 @@ import classNames from "classnames"; import { Tooltip } from "antd"; +import { useBooleanSetting } from "../utils/settings"; + import dayjs from "dayjs"; import TimeAgo from "react-timeago"; @@ -15,22 +17,30 @@ timeAgo?: boolean; small?: boolean; secondary?: boolean; + neverRelative?: boolean; } type Props = React.HTMLProps & OwnProps; -export function DateTime({ date, timeAgo, small, secondary, ...props }: Props): JSX.Element | null { +const RELATIVE_DATE_THRESHOLD = 1000 * 60 * 60 * 24 * 7; + +export function DateTime({ date, timeAgo, small, secondary, neverRelative, ...props }: Props): JSX.Element | null { + const showRelativeDates = useBooleanSetting("showRelativeDates"); + if (!date) return null; const realDate = typeof date === "string" ? new Date(date) : date; + const relative = Date.now() - realDate.getTime(); + + const isTimeAgo = timeAgo || (showRelativeDates && !neverRelative && relative < RELATIVE_DATE_THRESHOLD); const classes = classNames("date-time", props.className, { - "date-time-timeago": timeAgo, + "date-time-timeago": isTimeAgo, "date-time-small": small, "date-time-secondary": secondary }); return - {timeAgo + {isTimeAgo ? : dayjs(realDate).format("YYYY/MM/DD HH:mm:ss")} diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index 1e68cc1..4437fec 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -77,6 +77,15 @@ + + {/* Show relative dates */} + + + {/* Debug settings */} diff --git a/src/utils/settings.ts b/src/utils/settings.ts index 961aad2..5dd2931 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -27,6 +27,8 @@ readonly nameCopyButtons: boolean; /** Show copy buttons next to all block hashes. */ readonly blockHashCopyButtons: boolean; + /** Show relative dates instead of absolute ones when they are recent. */ + readonly showRelativeDates: boolean; /** Whether or not advanced wallet formats are enabled. */ readonly walletFormats: boolean; @@ -40,6 +42,7 @@ addressCopyButtons: false, nameCopyButtons: false, blockHashCopyButtons: false, + showRelativeDates: false, walletFormats: false };