-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed expiry function and the way it renders on UI in human-readable …
…format
- Loading branch information
1 parent
1b661d1
commit 3d45aed
Showing
4 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/site/src/utils/convertExpiryToHumanReadableFormat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const convertExpiryToHumanReadableFormat = ( | ||
expiry: number, | ||
): string | undefined => { | ||
const currentTimestamp = Math.floor(Date.now() / 1000); | ||
const remainingTimeInSeconds = expiry - currentTimestamp; | ||
|
||
if (remainingTimeInSeconds <= 0) { | ||
return undefined; | ||
} | ||
|
||
const minutes = Math.floor(remainingTimeInSeconds / 60) % 60; | ||
const hours = Math.floor(remainingTimeInSeconds / (60 * 60)) % 24; | ||
const days = Math.floor(remainingTimeInSeconds / (60 * 60 * 24)); | ||
|
||
if (remainingTimeInSeconds < 60 * 60) { | ||
return `${minutes} Min`; | ||
} | ||
if (remainingTimeInSeconds < 60 * 60 * 24) { | ||
return `${hours} Hour${hours === 1 ? '' : 's'}${ | ||
minutes > 0 ? ` ${minutes} Min${minutes === 1 ? '' : 's'}` : '' | ||
}`; | ||
} | ||
return `${days} Day${days === 1 ? '' : 's'}${ | ||
hours > 0 ? ` ${hours} Hour${hours === 1 ? '' : 's'}` : '' | ||
}`; | ||
}; |