diff --git a/common/utils.js b/common/utils.js index f5e0d244..b81443e5 100644 --- a/common/utils.js +++ b/common/utils.js @@ -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, @@ -223,4 +253,7 @@ module.exports = { httpPost, parseArgs, sleep, + dateToEta, + etaToDate, + getCurrentTimeInSeconds, }; diff --git a/evm/utils.js b/evm/utils.js index 35e3ab25..140d2c6b 100644 --- a/evm/utils.js +++ b/evm/utils.js @@ -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. @@ -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. * @@ -1113,9 +1085,6 @@ module.exports = { getConfigByChainId, sleep, printWalletInfo, - dateToEta, - etaToDate, - getCurrentTimeInSeconds, wasEventEmitted, isContract, isValidAddress,