Skip to content

Commit

Permalink
fix: fix the calculation of last updated time (#242)
Browse files Browse the repository at this point in the history
Because

- Last updated time (second) doesn't get rounded 

This commit

- Fix the calculation of last updated time
  • Loading branch information
EiffelFly committed Aug 19, 2022
1 parent 1923745 commit 75186a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/components/ui/TableCells/NameCell/NameCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const NameCell: FC<NameCellProps> = ({
const CellItem = () => (
<div className={cn("flex flex-row gap-x-2.5", width)}>
<div
className={cn("flex", displayStateIndicator ? "h-8 w-8" : "h-4 w-4")}
className={cn(
"flex",
displayStateIndicator ? "min-h-8 min-w-8" : "h-4 w-4"
)}
>
{displayStateIndicator ? (
<StateIcon
Expand All @@ -53,7 +56,9 @@ const NameCell: FC<NameCellProps> = ({
<div className="flex flex-col gap-y-2">
<h3 className={cn("text-instill-h3", lineClamp)}>{name}</h3>
{displayUpdateTime ? (
<p className="text-instillGrey50 text-instill-small">{`last update at ${time}`}</p>
<p className="text-instillGrey50 text-instill-small">
{`last updated at ${time}`}
</p>
) : null}
</div>
</div>
Expand Down
6 changes: 2 additions & 4 deletions src/utils/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const getHumanReadableStringFromTime = (
}

if (prev > next) {
throw new Error(
`prevTime - ${prevTime} is ahead of nextTime - ${nextTime}`
);
return "0 second ago";
}

const seconds = next - prev;
Expand All @@ -28,7 +26,7 @@ export const getHumanReadableStringFromTime = (
}

if (seconds < 60) {
return `${seconds} seconds ago`;
return `${Math.round(seconds)} seconds ago`;
}

const minutes = Math.floor(seconds / 60);
Expand Down

0 comments on commit 75186a8

Please sign in to comment.