Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions crypto/utils/slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

from crypto.configuration.network import Network

class Slot:
@staticmethod
def time():
"""Get the time difference between now and network start.

def get_time() -> int:
"""Get the time difference between now and network start.
Returns:
int: difference in seconds
"""
now = datetime.now(timezone.utc)

Returns:
int: difference in seconds
"""
now = datetime.now(timezone.utc)
seconds = int((now - Slot.epoch()).total_seconds())

seconds = int((now - get_epoch()).total_seconds())
return seconds

return seconds
@staticmethod
def epoch():
epoch_str = Network.get_network().epoch()
if epoch_str.endswith("Z"):
epoch_str = epoch_str[:-1] + "+00:00"


def get_epoch():
epoch_str = Network.get_network().epoch()
if epoch_str.endswith("Z"):
epoch_str = epoch_str[:-1] + "+00:00"

return datetime.fromisoformat(epoch_str)
return datetime.fromisoformat(epoch_str)
8 changes: 3 additions & 5 deletions tests/utils/test_slot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from datetime import datetime

from crypto.utils.slot import get_epoch, get_time

from crypto.utils.slot import Slot

def test_get_epoch():
result = get_epoch()
result = Slot.epoch()
assert isinstance(result, datetime)


def test_get_time():
result = get_time()
result = Slot.time()
assert isinstance(result, int)