move format_time to util
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import sys, time, datetime, re, threading
|
import sys, time, re, threading
|
||||||
from electrum.i18n import _, set_language
|
from electrum.i18n import _, set_language
|
||||||
from electrum.util import print_error, print_msg
|
from electrum.util import print_error, print_msg
|
||||||
import os.path, json, ast, traceback
|
import os.path, json, ast, traceback
|
||||||
@@ -35,7 +35,7 @@ from electrum.plugins import run_hook
|
|||||||
|
|
||||||
import icons_rc
|
import icons_rc
|
||||||
|
|
||||||
from electrum.util import format_satoshis, NotEnoughFunds
|
from electrum.util import format_satoshis, format_time, NotEnoughFunds
|
||||||
from electrum import Transaction
|
from electrum import Transaction
|
||||||
from electrum import mnemonic
|
from electrum import mnemonic
|
||||||
from electrum import util, bitcoin, commands, Interface, Wallet
|
from electrum import util, bitcoin, commands, Interface, Wallet
|
||||||
@@ -657,14 +657,6 @@ class ElectrumWindow(QMainWindow):
|
|||||||
run_hook('current_item_changed', a)
|
run_hook('current_item_changed', a)
|
||||||
|
|
||||||
|
|
||||||
def format_time(self, timestamp):
|
|
||||||
try:
|
|
||||||
time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
|
|
||||||
except Exception:
|
|
||||||
time_str = _("error")
|
|
||||||
return time_str
|
|
||||||
|
|
||||||
|
|
||||||
def update_history_tab(self):
|
def update_history_tab(self):
|
||||||
|
|
||||||
self.history_list.clear()
|
self.history_list.clear()
|
||||||
@@ -675,7 +667,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
continue # skip history in offline mode
|
continue # skip history in offline mode
|
||||||
|
|
||||||
if conf > 0:
|
if conf > 0:
|
||||||
time_str = self.format_time(timestamp)
|
time_str = format_time(timestamp)
|
||||||
if conf == -1:
|
if conf == -1:
|
||||||
time_str = 'unverified'
|
time_str = 'unverified'
|
||||||
icon = QIcon(":icons/unconfirmed.png")
|
icon = QIcon(":icons/unconfirmed.png")
|
||||||
@@ -913,7 +905,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
# only show requests for the current account
|
# only show requests for the current account
|
||||||
if address not in domain:
|
if address not in domain:
|
||||||
continue
|
continue
|
||||||
date = self.format_time(timestamp)
|
date = format_time(timestamp)
|
||||||
account = self.wallet.get_account_name(self.wallet.get_account_from_address(address))
|
account = self.wallet.get_account_name(self.wallet.get_account_from_address(address))
|
||||||
item = QTreeWidgetItem( [ date, account, address, message, self.format_amount(amount) if amount else ""])
|
item = QTreeWidgetItem( [ date, account, address, message, self.format_amount(amount) if amount else ""])
|
||||||
item.setFont(2, QFont(MONOSPACE_FONT))
|
item.setFont(2, QFont(MONOSPACE_FONT))
|
||||||
@@ -1430,7 +1422,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
domain, memo, amount, expiration_date, status, tx_hash = value
|
domain, memo, amount, expiration_date, status, tx_hash = value
|
||||||
if status == PR_UNPAID and expiration_date and expiration_date < time.time():
|
if status == PR_UNPAID and expiration_date and expiration_date < time.time():
|
||||||
status = PR_EXPIRED
|
status = PR_EXPIRED
|
||||||
date_str = datetime.datetime.fromtimestamp(expiration_date).isoformat(' ')[:-3]
|
date_str = format_time(expiration_date)
|
||||||
item = QTreeWidgetItem( [ date_str, domain, memo, self.format_amount(amount, whitespaces=True), ''] )
|
item = QTreeWidgetItem( [ date_str, domain, memo, self.format_amount(amount, whitespaces=True), ''] )
|
||||||
icon = QIcon(pr_icons.get(status))
|
icon = QIcon(pr_icons.get(status))
|
||||||
item.setIcon(4, icon)
|
item.setIcon(4, icon)
|
||||||
@@ -2477,11 +2469,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
tx_hash, confirmations, value, timestamp = item
|
tx_hash, confirmations, value, timestamp = item
|
||||||
if confirmations:
|
if confirmations:
|
||||||
if timestamp is not None:
|
if timestamp is not None:
|
||||||
try:
|
time_string = format_time(timestamp)
|
||||||
time_string = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
|
||||||
except [RuntimeError, TypeError, NameError] as reason:
|
|
||||||
time_string = "unknown"
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
time_string = "unknown"
|
time_string = "unknown"
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -131,6 +131,15 @@ def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespa
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def format_time(timestamp):
|
||||||
|
import datetime
|
||||||
|
try:
|
||||||
|
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
||||||
|
except:
|
||||||
|
time_str = "unknown"
|
||||||
|
return time_str
|
||||||
|
|
||||||
|
|
||||||
# Takes a timestamp and returns a string with the approximation of the age
|
# Takes a timestamp and returns a string with the approximation of the age
|
||||||
def age(from_date, since_date = None, target_tz=None, include_seconds=False):
|
def age(from_date, since_date = None, target_tz=None, include_seconds=False):
|
||||||
if from_date is None:
|
if from_date is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user