Skip to content

[feature-req] Add formatDateTime() Helper to Return ISO 8601 String to DateTimeLib.sol #1492

@Elliott-Green

Description

@Elliott-Green

💡 Proposed Feature

Add a helper function like the following to the DateTimeLib library to convert a UNIX timestamp into a human-readable ISO 8601-style string.

I'm a bit conflicted raising this, as it's very client specific to format or use the return date variables however they want, and this lib produces the data to do so. But on the other hand, for these 'one liner string return helpers' I would think this would be a common enough usecase for helper code to not be in client specific contracts and be inside the lib itself.

function formatDateTime(uint256 timestamp) external pure returns (string memory) {
      (
          uint256 year,
          uint256 month,
          uint256 day,
          uint256 hour,
          uint256 minute,
          uint256 second
      ) = DateTimeLib.timestampToDateTime(timestamp);

      return
          string.concat(
              _toString(year),
              "-",
              _toString(month),
              "-",
              _toString(day),
              " ",
              _toString(hour),
              ":",
              _toString(minute),
              ":",
              _toString(second),
              " UTC"
          );
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions