# SecondsOutside

Contains methods for working with a mapping from tick to 32 bit timestamp values, specifically seconds spent outside the tick.

The mapping uses int24 for keys since ticks are represented as int24 and there are 8 (2^3) values per word. Note "seconds outside" is always a relative measurement, only consistent for as long as a the lower tick and upper tick have gross liquidity greater than 0.

### Functions[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#functions) <a href="#functions" id="functions"></a>

#### initialize[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#initialize) <a href="#initialize" id="initialize"></a>

```solidity
  function initialize(
    mapping(int24 => uint256) self,
    int24 tick,
    int24 tickCurrent,
    int24 tickSpacing,
    uint32 time
  ) internal
```

Called the first time a tick is used to set the seconds outside value. Assumes the tick is not initialized.

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#parameters)

| Name          | Type                      | Description                                   |
| ------------- | ------------------------- | --------------------------------------------- |
| `self`        | mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| `tick`        | int24                     | the tick to be initialized                    |
| `tickCurrent` | int24                     | the current tick                              |
| `tickSpacing` | int24                     | the spacing between usable ticks              |
| `time`        | uint32                    | the current timestamp                         |

#### clear[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#clear) <a href="#clear" id="clear"></a>

```solidity
  function clear(
    mapping(int24 => uint256) self,
    int24 tick,
    int24 tickSpacing
  ) internal
```

Called when a tick is no longer used, to clear the seconds outside value of the tick

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#parameters-1)

| Name          | Type                      | Description                                   |
| ------------- | ------------------------- | --------------------------------------------- |
| `self`        | mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| `tick`        | int24                     | the tick to be cleared                        |
| `tickSpacing` | int24                     | the spacing between usable ticks              |

#### cross[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#cross) <a href="#cross" id="cross"></a>

```solidity
  function cross(
    mapping(int24 => uint256) self,
    int24 tick,
    int24 tickSpacing,
    uint32 time
  ) internal
```

Called when an initialized tick is crossed to update the seconds outside for that tick. Must be called every time an initialized tick is crossed

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#parameters-2)

| Name          | Type                      | Description                                      |
| ------------- | ------------------------- | ------------------------------------------------ |
| `self`        | mapping(int24 => uint256) | the packed mapping of tick to seconds outside    |
| `tick`        | int24                     | the tick to be crossed                           |
| `tickSpacing` | int24                     | the spacing between usable ticks                 |
| `time`        | uint32                    | the current block timestamp truncated to 32 bits |

#### get[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#get) <a href="#get" id="get"></a>

```solidity
  function get(
    mapping(int24 => uint256) self,
    int24 tick,
    int24 tickSpacing
  ) internal view returns (uint32)
```

Get the seconds outside for an initialized tick. Should be called only on initialized ticks.

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#parameters-3)

| Name          | Type                      | Description                                   |
| ------------- | ------------------------- | --------------------------------------------- |
| `self`        | mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| `tick`        | int24                     | the tick to get the seconds outside value for |
| `tickSpacing` | int24                     | the spacing between usable ticks              |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#return-values)

| Type   | Description                         |
| ------ | ----------------------------------- |
| uint32 | seconds outside value for that tick |

#### secondsInside[​](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#secondsinside) <a href="#secondsinside" id="secondsinside"></a>

```solidity
  function secondsInside(
    mapping(int24 => uint256) self,
    int24 tickLower,
    int24 tickUpper,
    int24 tickCurrent,
    int24 tickSpacing
  ) internal view returns (uint32)
```

Get the seconds inside a tick range, assuming both tickLower and tickUpper are initialized

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#parameters-4)

| Name          | Type                      | Description                                    |
| ------------- | ------------------------- | ---------------------------------------------- |
| `self`        | mapping(int24 => uint256) | the packed mapping of tick to seconds outside  |
| `tickLower`   | int24                     | the lower tick for which to get seconds inside |
| `tickUpper`   | int24                     | the upper tick for which to get seconds inside |
| `tickCurrent` | int24                     | the current tick                               |
| `tickSpacing` | int24                     | the spacing between usable ticks               |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/core/libraries/SecondsOutside#return-values-1)

| Name | Type   | Description                                                                                       |
| ---- | ------ | ------------------------------------------------------------------------------------------------- |
| `a`  | uint32 | relative seconds inside value that can be snapshotted and compared to a later snapshot to compute |

time spent between tickLower and tickUpper, i.e. time that a position's liquidity was in use.
