Skip to content

Commit

Permalink
chore: layer add sharedConvertTimestampToMilliseconds helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Dec 31, 2023
1 parent 0bb9259 commit d74f77e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions layer/utils/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ export const sharedToBalanceInWei = ({
return new BigNumberInBase(10).pow(decimalPlaces).times(value)
}

export const sharedConvertTimestampToMilliseconds = (
timestamp: number | string
): number => {
const timestampInBigNumber = new BigNumberInBase(timestamp)

if (timestamp.toString().length > 13) {
return timestampInBigNumber
.precision(13, BigNumber.ROUND_HALF_UP)
.toNumber()
}

if (timestamp.toString().length < 13) {
const trailingZeros = 13 - timestamp.toString().length

return timestampInBigNumber.times(10 ** trailingZeros).toNumber()
}

return timestampInBigNumber.toNumber()
}

export const sharedToBalanceInToken = ({
value,
decimalPlaces,
Expand Down

0 comments on commit d74f77e

Please sign in to comment.