Skip to content

Commit

Permalink
formatted seconds to min-sec
Browse files Browse the repository at this point in the history
  • Loading branch information
jagadeeswaran-zipstack committed Sep 5, 2024
1 parent a3e0f3d commit d2fae14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import CheckableTag from "antd/es/tag/CheckableTag";
import {
displayPromptResult,
formatNumberWithCommas,
formatTimeMinuteSeconds,
getFormattedTotalCost,
} from "../../../helpers/GetStaticData";
import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
Expand Down Expand Up @@ -211,7 +212,7 @@ function PromptOutput({
</Typography.Text>
<Typography.Text className="prompt-cost-item">
Time:
{timers[tokenUsageId] || 0}s
{formatTimeMinuteSeconds(timers[tokenUsageId]) || 0}
</Typography.Text>
<Typography.Text className="prompt-cost-item">
Cost: $
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/helpers/GetStaticData.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,23 @@ const formatNumberWithCommas = (number) => {
: formattedIntegerPart;
};

// utils/formatTime.js
const formatTimeMinuteSeconds = (seconds) => {
if (!seconds) {
return `0s`;
}

const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
// Pad single-digit seconds with leading zero
const formattedSeconds = secs < 10 ? `0${secs}` : secs;

if (seconds < 60) {
return `${formattedSeconds}s`;
}
return `${mins}m ${formattedSeconds}s`;
};

export {
CONNECTOR_TYPE_MAP,
O_AUTH_PROVIDERS,
Expand Down Expand Up @@ -563,4 +580,5 @@ export {
getDocIdFromKey,
displayURL,
formatNumberWithCommas,
formatTimeMinuteSeconds,
};

0 comments on commit d2fae14

Please sign in to comment.