Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Time

*This library provides helpers for manipulating time-related objects. It uses the following types:

  • uint48 for timepoints
  • uint32 for durations While the library doesn't provide specific types for timepoints and duration, it does provide:
  • a Delay type to represent duration that can be programmed to change value automatically at a given point
  • additional helper functions*

Functions

timestamp

Get the block timestamp as a Timepoint.

function timestamp() internal view returns (uint48);

blockNumber

Get the block number as a Timepoint.

function blockNumber() internal view returns (uint48);

toDelay

Wrap a duration into a Delay to add the one-step "update in the future" feature

function toDelay(uint32 duration) internal pure returns (Delay);

_getFullAt

Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.

function _getFullAt(Delay self, uint48 timepoint)
    private
    pure
    returns (uint32 valueBefore, uint32 valueAfter, uint48 effect);

getFull

Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the effect timepoint is 0, then the pending value should not be considered.

function getFull(Delay self) internal view returns (uint32 valueBefore, uint32 valueAfter, uint48 effect);

get

Get the current value.

function get(Delay self) internal view returns (uint32);

withUpdate

Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the new delay becomes effective.

function withUpdate(Delay self, uint32 newValue, uint32 minSetback)
    internal
    view
    returns (Delay updatedDelay, uint48 effect);

unpack

Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).

function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect);

pack

pack the components into a Delay object.

function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay);