Skip to content

Commit

Permalink
chore: move dateToEta, etaToDate, getCurrentTimeInSeconds
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Jul 26, 2024
1 parent bbfa304 commit d4067fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
33 changes: 33 additions & 0 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@ function isValidTimeFormat(timeString) {
return regex.test(timeString);
}

const dateToEta = (utcTimeString) => {
if (utcTimeString === '0') {
return 0;
}

const date = new Date(utcTimeString + 'Z');

if (isNaN(date.getTime())) {
throw new Error(`Invalid date format provided: ${utcTimeString}`);
}

return Math.floor(date.getTime() / 1000);
};

const etaToDate = (timestamp) => {
const date = new Date(timestamp * 1000);

if (isNaN(date.getTime())) {
throw new Error(`Invalid timestamp provided: ${timestamp}`);
}

return date.toISOString().slice(0, 19);
};

const getCurrentTimeInSeconds = () => {
const now = new Date();
const currentTimeInSecs = Math.floor(now.getTime() / 1000);
return currentTimeInSecs;
};

module.exports = {
loadConfig,
saveConfig,
Expand All @@ -223,4 +253,7 @@ module.exports = {
httpPost,
parseArgs,
sleep,
dateToEta,
etaToDate,
getCurrentTimeInSeconds,
};
33 changes: 1 addition & 32 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ const isBytes32Array = (arr) => {
return true;
};

const getCurrentTimeInSeconds = () => {
const now = new Date();
const currentTimeInSecs = Math.floor(now.getTime() / 1000);
return currentTimeInSecs;
};


/**
* Determines if a given input is a valid keccak256 hash.
Expand Down Expand Up @@ -631,30 +627,6 @@ const deployContract = async (
}
};

const dateToEta = (utcTimeString) => {
if (utcTimeString === '0') {
return 0;
}

const date = new Date(utcTimeString + 'Z');

if (isNaN(date.getTime())) {
throw new Error(`Invalid date format provided: ${utcTimeString}`);
}

return Math.floor(date.getTime() / 1000);
};

const etaToDate = (timestamp) => {
const date = new Date(timestamp * 1000);

if (isNaN(date.getTime())) {
throw new Error(`Invalid timestamp provided: ${timestamp}`);
}

return date.toISOString().slice(0, 19);
};

/**
* Check if a specific event was emitted in a transaction receipt.
*
Expand Down Expand Up @@ -1113,9 +1085,6 @@ module.exports = {
getConfigByChainId,
sleep,
printWalletInfo,
dateToEta,
etaToDate,
getCurrentTimeInSeconds,
wasEventEmitted,
isContract,
isValidAddress,
Expand Down

0 comments on commit d4067fd

Please sign in to comment.