Skip to content
Snippets Groups Projects
Commit 0393c975 authored by roadscape's avatar roadscape
Browse files

define block_date and block_num

parent 5a8a7600
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,14 @@ def legacy_amount(value): ...@@ -61,6 +61,14 @@ def legacy_amount(value):
tmpl = ("%%.%df %%s" % prec) tmpl = ("%%.%df %%s" % prec)
return tmpl % (amt, asset) return tmpl % (amt, asset)
def block_num(block):
"""Given a block object, returns the block number."""
return int(block['block_id'][:8], base=16)
def block_date(block):
"""Parse block timestamp into datetime object."""
return parse_time(block['timestamp'])
def parse_time(block_time): def parse_time(block_time):
"""Convert chain date into datetime object.""" """Convert chain date into datetime object."""
return datetime.strptime(block_time, '%Y-%m-%dT%H:%M:%S') return datetime.strptime(block_time, '%Y-%m-%dT%H:%M:%S')
......
...@@ -2,6 +2,8 @@ from datetime import datetime ...@@ -2,6 +2,8 @@ from datetime import datetime
from decimal import Decimal from decimal import Decimal
from hive.utils.normalize import ( from hive.utils.normalize import (
block_num,
block_date,
vests_amount, vests_amount,
steem_amount, steem_amount,
sbd_amount, sbd_amount,
...@@ -15,6 +17,14 @@ from hive.utils.normalize import ( ...@@ -15,6 +17,14 @@ from hive.utils.normalize import (
safe_img_url, safe_img_url,
) )
def test_block_num():
block = dict(block_id='013c33f88c643c92a7352b52efde7237f4d4ee0b')
assert block_num(block) == 20722680
def test_block_date():
block = dict(timestamp='2018-03-16T10:08:42')
assert block_date(block) == datetime(2018, 3, 16, 10, 8, 42)
def test_vests_amount(): def test_vests_amount():
assert vests_amount('4.549292 VESTS') == Decimal('4.549292') assert vests_amount('4.549292 VESTS') == Decimal('4.549292')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment