From 1ff317cd849343b0058926b384897c4722b93107 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:14:58 +0100 Subject: [PATCH] refactor: slot epoch int return type --- crypto/utils/slot.py | 10 ++++------ tests/utils/test_slot.py | 4 +--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crypto/utils/slot.py b/crypto/utils/slot.py index 502366c..875b297 100644 --- a/crypto/utils/slot.py +++ b/crypto/utils/slot.py @@ -4,7 +4,7 @@ class Slot: @staticmethod - def time(): + def time() -> int: """Get the time difference between now and network start. Returns: @@ -12,14 +12,12 @@ def time(): """ now = datetime.now(timezone.utc) - seconds = int((now - Slot.epoch()).total_seconds()) - - return seconds + return int(now.timestamp() - Slot.epoch()) @staticmethod - def epoch(): + def epoch() -> int: epoch_str = Network.get_network().epoch() if epoch_str.endswith("Z"): epoch_str = epoch_str[:-1] + "+00:00" - return datetime.fromisoformat(epoch_str) + return int(datetime.fromisoformat(epoch_str).timestamp()) diff --git a/tests/utils/test_slot.py b/tests/utils/test_slot.py index 7068fa2..7119784 100644 --- a/tests/utils/test_slot.py +++ b/tests/utils/test_slot.py @@ -1,10 +1,8 @@ -from datetime import datetime - from crypto.utils.slot import Slot def test_get_epoch(): result = Slot.epoch() - assert isinstance(result, datetime) + assert isinstance(result, int) def test_get_time(): result = Slot.time()