File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from crypto .configuration .network import Network
44
5+ class Slot :
6+ @staticmethod
7+ def time ():
8+ """Get the time difference between now and network start.
59
6- def get_time () -> int :
7- """Get the time difference between now and network start.
10+ Returns:
11+ int: difference in seconds
12+ """
13+ now = datetime .now (timezone .utc )
814
9- Returns:
10- int: difference in seconds
11- """
12- now = datetime .now (timezone .utc )
15+ seconds = int ((now - Slot .epoch ()).total_seconds ())
1316
14- seconds = int (( now - get_epoch ()). total_seconds ())
17+ return seconds
1518
16- return seconds
19+ @staticmethod
20+ def epoch ():
21+ epoch_str = Network .get_network ().epoch ()
22+ if epoch_str .endswith ("Z" ):
23+ epoch_str = epoch_str [:- 1 ] + "+00:00"
1724
18-
19- def get_epoch ():
20- epoch_str = Network .get_network ().epoch ()
21- if epoch_str .endswith ("Z" ):
22- epoch_str = epoch_str [:- 1 ] + "+00:00"
23-
24- return datetime .fromisoformat (epoch_str )
25+ return datetime .fromisoformat (epoch_str )
Original file line number Diff line number Diff line change 11from datetime import datetime
22
3- from crypto .utils .slot import get_epoch , get_time
4-
3+ from crypto .utils .slot import Slot
54
65def test_get_epoch ():
7- result = get_epoch ()
6+ result = Slot . epoch ()
87 assert isinstance (result , datetime )
98
10-
119def test_get_time ():
12- result = get_time ()
10+ result = Slot . time ()
1311 assert isinstance (result , int )
You can’t perform that action at this time.
0 commit comments