Time

cometa.time.slot_from_unix_time(network, unix_time)[source]

Computes the Cardano network slot for a given Unix time.

This function calculates the slot number on the Cardano network corresponding to a specified Unix timestamp. Since slot duration may vary across different networks and over time, this computation requires both the network magic and the Unix time.

Parameters:
  • network (NetworkMagic | int) – The network magic identifying the specific Cardano network. Can be a NetworkMagic enum value or an integer.

  • unix_time (int) – The Unix timestamp in seconds for which to compute the slot.

Returns:

The computed slot number representing the slot at the specified Unix time.

Return type:

int

Example

>>> from cometa import NetworkMagic, slot_from_unix_time
>>> slot = slot_from_unix_time(NetworkMagic.MAINNET, 1700000000)
>>> print(f"Slot: {slot}")

Note

Slot duration and epoch boundaries may vary across networks and can change over time. This function takes these network-specific configurations into account.


cometa.time.unix_time_from_slot(network, slot)[source]

Computes the Unix time corresponding to a given Cardano network slot.

This function calculates the Unix timestamp for a specified slot number on the Cardano network. Slot-to-time mapping depends on the network’s specific slot duration and other time-related parameters that may vary across different Cardano networks and epochs.

Parameters:
  • network (NetworkMagic | int) – The network magic identifying the specific Cardano network. Can be a NetworkMagic enum value or an integer.

  • slot (int) – The slot number for which to compute the Unix time.

Returns:

The computed Unix timestamp in seconds representing the time at the specified slot.

Return type:

int

Example

>>> from cometa import NetworkMagic, unix_time_from_slot
>>> unix_time = unix_time_from_slot(NetworkMagic.MAINNET, 500000)
>>> print(f"Unix time: {unix_time}")

Note

The conversion relies on the network’s configuration, as different networks and epochs may have varying slot durations, affecting the calculated Unix time.