electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 6fa7f57f10889068d08f6bc8625b73490d8d5be9
parent 0fad7cd5e1d3499d5409a44d0f99c02f1f354459
Author: ThomasV <thomasv@gitorious>
Date:   Mon, 13 Jul 2015 20:47:11 +0200

express expiration dates in natural language

Diffstat:
Mgui/qt/main_window.py | 6+++---
Mlib/util.py | 37+++++++++++++++++++++----------------
2 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -681,7 +681,7 @@ class ElectrumWindow(QMainWindow): return addr = str(item.text(2)) req = self.wallet.receive_requests[addr] - expires = _('Never') if req.get('expiration') is None else format_time(req['timestamp'] + req['expiration']) + expires = _('Never') if req.get('expiration') is None else util.age(req['timestamp'] + req['expiration']) amount = req['amount'] message = self.wallet.labels.get(addr, '') self.receive_address_e.setText(addr) @@ -990,7 +990,7 @@ class ElectrumWindow(QMainWindow): self.invoices_label = QLabel(_('Invoices')) self.invoices_list = MyTreeWidget(self, self.invoices_list_menu, - [_('Date'), _('Requestor'), _('Description'), _('Amount'), _('Status')], 2) + [_('Expires'), _('Requestor'), _('Description'), _('Amount'), _('Status')], 2) self.invoices_list.header().setResizeMode(1, QHeaderView.Interactive) self.invoices_list.setColumnWidth(1, 200) @@ -1398,7 +1398,7 @@ class ElectrumWindow(QMainWindow): key = pr.get_id() status = self.invoices.get_status(key) requestor = pr.get_requestor() - date_str = format_time(pr.get_expiration_date()) + date_str = util.age(pr.get_expiration_date()) item = QTreeWidgetItem( [ date_str, requestor, pr.memo, self.format_amount(pr.get_amount(), whitespaces=True), pr_tooltips.get(status,'')] ) item.setIcon(4, QIcon(pr_icons.get(status))) item.setData(0, Qt.UserRole, key) diff --git a/lib/util.py b/lib/util.py @@ -157,7 +157,12 @@ def age(from_date, since_date = None, target_tz=None, include_seconds=False): if since_date is None: since_date = datetime.now(target_tz) - distance_in_time = since_date - from_date + td = time_difference(from_date - since_date, include_seconds) + return td + " ago" if from_date < since_date else "in " + td + + +def time_difference(distance_in_time, include_seconds): + #distance_in_time = since_date - from_date distance_in_seconds = int(round(abs(distance_in_time.days * 86400 + distance_in_time.seconds))) distance_in_minutes = int(round(distance_in_seconds/60)) @@ -165,36 +170,36 @@ def age(from_date, since_date = None, target_tz=None, include_seconds=False): if include_seconds: for remainder in [5, 10, 20]: if distance_in_seconds < remainder: - return "less than %s seconds ago" % remainder + return "less than %s seconds" % remainder if distance_in_seconds < 40: - return "half a minute ago" + return "half a minute" elif distance_in_seconds < 60: - return "less than a minute ago" + return "less than a minute" else: - return "1 minute ago" + return "1 minute" else: if distance_in_minutes == 0: - return "less than a minute ago" + return "less than a minute" else: - return "1 minute ago" + return "1 minute" elif distance_in_minutes < 45: - return "%s minutes ago" % distance_in_minutes + return "%s minutes" % distance_in_minutes elif distance_in_minutes < 90: - return "about 1 hour ago" + return "about 1 hour" elif distance_in_minutes < 1440: - return "about %d hours ago" % (round(distance_in_minutes / 60.0)) + return "about %d hours" % (round(distance_in_minutes / 60.0)) elif distance_in_minutes < 2880: - return "1 day ago" + return "1 day" elif distance_in_minutes < 43220: - return "%d days ago" % (round(distance_in_minutes / 1440)) + return "%d days" % (round(distance_in_minutes / 1440)) elif distance_in_minutes < 86400: - return "about 1 month ago" + return "about 1 month" elif distance_in_minutes < 525600: - return "%d months ago" % (round(distance_in_minutes / 43200)) + return "%d months" % (round(distance_in_minutes / 43200)) elif distance_in_minutes < 1051200: - return "about 1 year ago" + return "about 1 yeas" else: - return "over %d years ago" % (round(distance_in_minutes / 525600)) + return "over %d years" % (round(distance_in_minutes / 525600)) block_explorer_info = { 'Blockchain.info': ('https://blockchain.info',