Skip to content

Commit

Permalink
Update calculateUsedTimePercentage to handle invalid expireTimestamp …
Browse files Browse the repository at this point in the history
…formats and log input
  • Loading branch information
MatinDehghanian committed Nov 27, 2024
1 parent fabf28d commit ddc734f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export const calculateRemainingTime = (expire) => {
return `${minutes} دقیقه`;
};
export const calculateUsedTimePercentage = (expireTimestamp) => {
console.log(expireTimestamp);

let expireTimeInSeconds;

if (typeof expireTimestamp === "string") {
Expand All @@ -128,7 +130,7 @@ export const calculateUsedTimePercentage = (expireTimestamp) => {
} else if (typeof expireTimestamp === "number") {
expireTimeInSeconds = expireTimestamp;
} else {
throw new Error("Invalid expireTimestamp format");
return 0;
}

const remainingSeconds = expireTimeInSeconds - Math.floor(Date.now() / 1000);
Expand Down

0 comments on commit ddc734f

Please sign in to comment.