Skip to content

Commit

Permalink
fix: update date format
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Jul 15, 2024
1 parent 4f413ba commit 1a00cc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ui/components/app/nft-details/nft-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '../../../helpers/constants/design-system';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
formatDateWithSuffix,
formatDate,
getAssetImageURL,
shortenAddress,
} from '../../../helpers/utils/util';
Expand Down Expand Up @@ -69,7 +69,10 @@ import {
import { MetaMetricsContext } from '../../../contexts/metametrics';
import { Content, Footer, Page } from '../../multichain/pages/page';
import { formatCurrency } from '../../../helpers/utils/confirm-tx.util';
import { getPricePrecision } from '../../../pages/asset/util';
import {
getPricePrecision,
getShortDateFormatterV2,
} from '../../../pages/asset/util';
import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps';
import NftDetailInformationRow from './nft-detail-information-row';
import NftDetailInformationFrame from './nft-detail-information-frame';
Expand Down Expand Up @@ -237,6 +240,11 @@ export default function NftDetails({ nft }: { nft: Nft }) {
return Math.floor(date.getTime() / 1000);
};

const getFormattedDate = (dateString: number) => {
const date = new Date(dateString * 1000).getTime();
return getShortDateFormatterV2().format(date);
};

const hasPriceSection = getCurrentHighestBidValue() || lastSale?.timestamp;
const hasCollectionSection =
collection?.name || collection?.tokenCount || collection?.creator;
Expand Down Expand Up @@ -542,7 +550,7 @@ export default function NftDetails({ nft }: { nft: Nft }) {
title={t('dateCreated')}
value={
collection?.contractDeployedAt
? formatDateWithSuffix(
? getFormattedDate(
getDateCreatedTimestamp(collection?.contractDeployedAt),
)
: undefined
Expand All @@ -566,7 +574,7 @@ export default function NftDetails({ nft }: { nft: Nft }) {
title={t('lastSold')}
value={
lastSale?.timestamp
? formatDateWithSuffix(lastSale?.timestamp)
? getFormattedDate(lastSale?.timestamp)
: undefined
}
icon={
Expand Down
8 changes: 8 additions & 0 deletions ui/pages/asset/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export const getShortDateFormatter = () =>
minute: 'numeric',
});

/** Formats a datetime in a short human readable format like 'Feb 8, 2030' */
export const getShortDateFormatterV2 = () =>
Intl.DateTimeFormat(navigator.language, {
year: 'numeric',
month: 'short',
day: 'numeric',
});

/**
* Formats a potentially large number to the nearest unit.
* e.g. 1T for trillions, 2.3B for billions, 4.56M for millions, 7,890 for thousands, etc.
Expand Down

0 comments on commit 1a00cc1

Please sign in to comment.