diff --git a/crypto/utils/slot.py b/crypto/utils/slot.py index c0aa763..502366c 100644 --- a/crypto/utils/slot.py +++ b/crypto/utils/slot.py @@ -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) diff --git a/tests/utils/test_slot.py b/tests/utils/test_slot.py index fa17037..7068fa2 100644 --- a/tests/utils/test_slot.py +++ b/tests/utils/test_slot.py @@ -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)