-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from 0xsequence/clawback-metadata
Clawback metadata
- Loading branch information
Showing
3 changed files
with
181 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import {LibString} from "solady/utils/LibString.sol"; | ||
|
||
|
||
library Duration { | ||
using LibString for *; | ||
|
||
function format(uint256 totalSeconds) internal pure returns (string memory) { | ||
uint256 d = totalSeconds / (24 * 60 * 60); | ||
uint256 h = (totalSeconds % (24 * 60 * 60)) / (60 * 60); | ||
uint256 m = (totalSeconds % (60 * 60)) / 60; | ||
uint256 s = totalSeconds % 60; | ||
|
||
string memory result; | ||
|
||
if (d > 0) { | ||
result = string(abi.encodePacked(d.toString(), " days")); | ||
} | ||
if (h > 0) { | ||
result = bytes(result).length > 0 | ||
? string(abi.encodePacked(result, ", ", h.toString(), " hours")) | ||
: string(abi.encodePacked(h.toString(), " hours")); | ||
} | ||
if (m > 0) { | ||
result = bytes(result).length > 0 | ||
? string(abi.encodePacked(result, ", ", m.toString(), " minutes")) | ||
: string(abi.encodePacked(m.toString(), " minutes")); | ||
} | ||
if (s > 0) { | ||
result = bytes(result).length > 0 | ||
? string(abi.encodePacked(result, ", ", s.toString(), " seconds")) | ||
: string(abi.encodePacked(s.toString(), " seconds")); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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