Skip to main content

_deriveNumberFrom

Contract: JBFundingCycleStore

The number of the next funding cycle given the specified funding cycle.

Definition

function _deriveNumberFrom(JBFundingCycle memory _baseFundingCycle, uint256 _start)
private
pure
returns (uint256) { ... }
  • Arguments:
    • _baseFundingCycle is the JBFundingCycle to base the calculation on.
    • _start is the start time of the funding cycle to derive a number for.
  • The view function is private to this contract.
  • The view function does not alter state on the blockchain.
  • The function returns the funding cycle number.

Body

  1. If the base funding cycle doesn't have a duration, the next number is 1 more than the base's number.

    // A subsequent cycle to one with a duration of 0 should be the next number.
    if (_baseFundingCycle.duration == 0) return _baseFundingCycle.number + 1;
  2. Get a reference to how long after the base funding cycle's start the specified start time is.

    // The difference between the start of the base funding cycle and the proposed start.
    uint256 _startDistance = _start - _baseFundingCycle.start;
  3. Return the number of base cycles that fit in the base distance.

    // Find the number of base cycles that fit in the start distance.
    return _baseFundingCycle.number + (_startDistance / _baseFundingCycle.duration);