Skip to content

Commit f26b2a8

Browse files
authored
refactor: slot epoch int return type (#168)
1 parent a02f70e commit f26b2a8

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

crypto/utils/slot.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44

55
class Slot:
66
@staticmethod
7-
def time():
7+
def time() -> int:
88
"""Get the time difference between now and network start.
99
1010
Returns:
1111
int: difference in seconds
1212
"""
1313
now = datetime.now(timezone.utc)
1414

15-
seconds = int((now - Slot.epoch()).total_seconds())
16-
17-
return seconds
15+
return int(now.timestamp() - Slot.epoch())
1816

1917
@staticmethod
20-
def epoch():
18+
def epoch() -> int:
2119
epoch_str = Network.get_network().epoch()
2220
if epoch_str.endswith("Z"):
2321
epoch_str = epoch_str[:-1] + "+00:00"
2422

25-
return datetime.fromisoformat(epoch_str)
23+
return int(datetime.fromisoformat(epoch_str).timestamp())

tests/utils/test_slot.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from datetime import datetime
2-
31
from crypto.utils.slot import Slot
42

53
def test_get_epoch():
64
result = Slot.epoch()
7-
assert isinstance(result, datetime)
5+
assert isinstance(result, int)
86

97
def test_get_time():
108
result = Slot.time()

0 commit comments

Comments
 (0)