Skip to content

Commit

Permalink
Merge pull request #258 from Blobscan/fix/timestamp-normalization
Browse files Browse the repository at this point in the history
fix(web): resolve timestamp normalization issue
  • Loading branch information
0xGabi authored Mar 5, 2024
2 parents e3fe655 + 8c49f05 commit 51acb55
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-ducks-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/web": patch
---

Resolved timestamp normalization issue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import { animated, useSpring } from "@react-spring/web";
import "react-loading-skeleton/dist/skeleton.css";
import Skeleton from "react-loading-skeleton";

import dayjs from "@blobscan/dayjs";

import type { Block } from "~/types";
import {
buildAddressRoute,
buildBlobRoute,
buildBlockRoute,
buildTransactionRoute,
formatBytes,
normalizeTimestamp,
} from "~/utils";
import { Link } from "../../Link";
import { SurfaceCardBase } from "./SurfaceCardBase";
Expand Down Expand Up @@ -164,7 +163,7 @@ const BlobTransactionCard: FC<BlobTransactionCardProps> = function ({
<Link href={buildBlockRoute(number)}>{number}</Link>
</div>
<div className="text-xs italic text-contentSecondary-light dark:text-contentSecondary-dark">
{dayjs(timestamp).fromNow()}
{normalizeTimestamp(timestamp).fromNow()}
</div>
</div>
)}
Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/components/Cards/SurfaceCards/BlockCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import type { FC } from "react";
import "react-loading-skeleton/dist/skeleton.css";
import Skeleton from "react-loading-skeleton";

import dayjs from "@blobscan/dayjs";

import type { Block } from "~/types";
import { buildBlockRoute } from "~/utils";
import { buildBlockRoute, normalizeTimestamp } from "~/utils";
import { Link } from "../../Link";
import { CardHeader } from "../Card";
import { SurfaceCardBase } from "./SurfaceCardBase";
Expand Down Expand Up @@ -40,7 +38,7 @@ const BlockCard: FC<Partial<BlockCardProps>> = function ({
<div className="pt-2 text-sm">
{timestamp ? (
<div className="mb-2 text-xs italic text-contentSecondary-light dark:text-contentSecondary-dark">
{dayjs(timestamp).fromNow()}
{normalizeTimestamp(timestamp).fromNow()}
</div>
) : (
<Skeleton width={100} />
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import dayjs from "@blobscan/dayjs";

export function normalizeTimestamp(timestamp: number | Date) {
return typeof timestamp === "number"
? dayjs.unix(timestamp)
: dayjs(timestamp);
}

export function formatTimestamp(timestamp: number | Date) {
const unixHandler =
typeof timestamp === "number" ? dayjs.unix(timestamp) : dayjs(timestamp);
const unixHandler = normalizeTimestamp(timestamp);

return `${unixHandler.fromNow()} (${unixHandler.format(
"MMM D, YYYY h:mm AZ"
Expand Down

0 comments on commit 51acb55

Please sign in to comment.