Problem: Issue #1, timespec not present in <= Python 3.5

This commit is contained in:
Daniel Edgecumbe 2017-10-02 17:29:06 +01:00
parent 7254ad8286
commit a6ae0e464e
5 changed files with 15 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import asyncio
# from decimal import Decimal
import view
from util import isoformatseconds
class BlockStore(object):
@ -156,7 +157,7 @@ class BlockView(view.View):
self._pad.addstr(0, 46, "[J/K: browse, HOME/END: quicker, L: best, TAB: manual]", CYELLOW)
self._pad.addstr(0, 1, "Time {}".format(
datetime.datetime.utcfromtimestamp(block["time"]).isoformat(timespec="seconds")
isoformatseconds(datetime.datetime.utcfromtimestamp(block["time"]))
), CBOLD)
self._pad.addstr(0, 31, "Height {}".format(block["height"]), CBOLD)

View File

@ -5,6 +5,7 @@
import curses
from macros import MODES, MIN_WINDOW_SIZE
from util import isoformatseconds
class FooterView(object):
@ -41,7 +42,7 @@ class FooterView(object):
x += len(mode_string) + 5
if self._dt:
self._pad.addstr(0, 81, self._dt.isoformat(timespec="seconds")[:19], CYELLOW + CBOLD)
self._pad.addstr(0, 81, isoformatseconds(self._dt)[:19], CYELLOW + CBOLD)
await self._draw_pad_to_screen()

View File

@ -8,6 +8,7 @@ import asyncio
import view
from macros import TX_VERBOSE_MODE
from util import isoformatseconds
class TransactionStore(object):
@ -69,7 +70,7 @@ class TransactionView(view.View):
CBOLD = curses.A_BOLD
self._pad.addstr(0, 1, "time {}".format(
datetime.datetime.utcfromtimestamp(transaction["time"]).isoformat(timespec="seconds")
isoformatseconds(datetime.datetime.utcfromtimestamp(transaction["time"]))
), CBOLD)
self._pad.addstr(1, 1, "size {}b".format(transaction["size"]), CBOLD)
self._pad.addstr(1, 15, "vsize {}b".format(transaction["vsize"]), CBOLD)

7
util.py Normal file
View File

@ -0,0 +1,7 @@
def isoformatseconds(dt):
try:
return dt.isoformat(timespec="seconds")
except TypeError:
# Python 3.5 and below
# 'timespec' is an invalid keyword argument for this function
return dt.isoformat().split(".")[0]

View File

@ -7,6 +7,7 @@ import curses
import asyncio
import view
from util import isoformatseconds
class WalletView(view.View):
_mode_name = "wallet"
@ -56,7 +57,7 @@ class WalletView(view.View):
self._pad.addstr(2+((i-offset)*3)+1, 1, " " * 98, color)
self._pad.addstr(2+((i-offset)*3), 1, "{}".format(
datetime.datetime.utcfromtimestamp(tx["timereceived"]).isoformat(timespec="seconds")
isoformatseconds(datetime.datetime.utcfromtimestamp(tx["timereceived"]))
), color)
self._pad.addstr(2+((i-offset)*3), 30, "block: {: 7d}".format(tx["blockindex"]), color)
self._pad.addstr(2+((i-offset)*3), 81, "{: 15.8f} BTC".format(