From 0c7d8646d4dba5f1d6c5573d94bb83cd0fbaefd1 Mon Sep 17 00:00:00 2001 From: f321x Date: Thu, 14 Aug 2025 09:49:27 +0200 Subject: [PATCH 1/2] qml: stop showing seconds in tx history timestamps Reduces the precision of the date field in the qml transaction history list to minutes. Seconds don't seem very useful in practice and add clutter to the UI. This adapts the behaviour to the Qt GUI. --- electrum/gui/qml/qetransactionlistmodel.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/electrum/gui/qml/qetransactionlistmodel.py b/electrum/gui/qml/qetransactionlistmodel.py index 3b94d25bf..20d502951 100644 --- a/electrum/gui/qml/qetransactionlistmodel.py +++ b/electrum/gui/qml/qetransactionlistmodel.py @@ -162,7 +162,8 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): return item - def get_section_by_timestamp(self, timestamp): + @staticmethod + def get_section_by_timestamp(timestamp): txts = datetime.fromtimestamp(timestamp) today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) @@ -177,14 +178,15 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): else: return 'older' - def format_date_by_section(self, section, date): + @staticmethod + def format_date_by_section(section: str, date: datetime): # TODO: l10n dfmt = { - 'today': '%H:%M:%S', - 'yesterday': '%H:%M:%S', - 'lastweek': '%a, %H:%M:%S', - 'lastmonth': '%a %d, %H:%M:%S', - 'older': '%Y-%m-%d %H:%M:%S' + 'today': '%H:%M', + 'yesterday': '%H:%M', + 'lastweek': '%a, %H:%M', + 'lastmonth': '%a %d, %H:%M', + 'older': '%Y-%m-%d %H:%M' } if section not in dfmt: section = 'older' From 292ade89534480da6593f391f2104231701b910d Mon Sep 17 00:00:00 2001 From: f321x Date: Thu, 14 Aug 2025 10:10:42 +0200 Subject: [PATCH 2/2] tests: unittest QETransactionListModel date format adds unittests for the date formatting and categorization in QETransactionListModel --- tests/test_qml_qetransactionlistmodel.py | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test_qml_qetransactionlistmodel.py diff --git a/tests/test_qml_qetransactionlistmodel.py b/tests/test_qml_qetransactionlistmodel.py new file mode 100644 index 000000000..7c2b8afa5 --- /dev/null +++ b/tests/test_qml_qetransactionlistmodel.py @@ -0,0 +1,71 @@ +from datetime import datetime +from unittest.mock import patch + +from electrum.gui.qml.qetransactionlistmodel import QETransactionListModel + +from . import ElectrumTestCase + + +class TestQETransactionListModel(ElectrumTestCase): + + def test_get_section_by_timestamp(self): + f = QETransactionListModel.get_section_by_timestamp + + mock_today = datetime(2023, 6, 15, 0, 0, 0, 0) + with patch('electrum.gui.qml.qetransactionlistmodel.datetime') as mock_dt: + mock_dt.today.return_value = mock_today + mock_dt.fromtimestamp = datetime.fromtimestamp + + today_ts = datetime(2023, 6, 15, 10, 30, 0).timestamp() + self.assertEqual(f(today_ts), 'today') + + today_edge_ts = datetime(2023, 6, 15, 0, 0, 1).timestamp() + self.assertEqual(f(today_edge_ts), 'today') + + yesterday_ts = datetime(2023, 6, 14, 15, 0, 0).timestamp() + self.assertEqual(f(yesterday_ts), 'yesterday') + + yesterday_edge_ts = datetime(2023, 6, 13, 23, 59, 59).timestamp() + self.assertEqual(f(yesterday_edge_ts), 'lastweek') + + lastweek_ts = datetime(2023, 6, 12, 12, 0, 0).timestamp() + self.assertEqual(f(lastweek_ts), 'lastweek') + + lastweek_boundary_ts = datetime(2023, 6, 8, 12, 0, 0).timestamp() + self.assertEqual(f(lastweek_boundary_ts), 'lastweek') + + lastmonth_ts = datetime(2023, 6, 5, 9, 0, 0).timestamp() + self.assertEqual(f(lastmonth_ts), 'lastmonth') + + lastmonth_boundary_ts = datetime(2023, 5, 15, 8, 0, 0).timestamp() + self.assertEqual(f(lastmonth_boundary_ts), 'lastmonth') + + older_ts = datetime(2023, 5, 14, 10, 0, 0).timestamp() + self.assertEqual(f(older_ts), 'older') + + much_older_ts = datetime(2022, 1, 1, 0, 0, 0).timestamp() + self.assertEqual(f(much_older_ts), 'older') + + def test_format_date_by_section(self): + f = QETransactionListModel.format_date_by_section + + test_date = datetime(2023, 6, 15, 14, 30, 45) + + result = f('today', test_date) + self.assertEqual(result, '14:30') + + result = f('yesterday', test_date) + self.assertEqual(result, '14:30') + + result = f('lastweek', test_date) + self.assertEqual(result, 'Thu, 14:30') + + result = f('lastmonth', test_date) + self.assertEqual(result, 'Thu 15, 14:30') + + result = f('older', test_date) + self.assertEqual(result, '2023-06-15 14:30') + + result = f('unknown_section', test_date) + self.assertEqual(result, '2023-06-15 14:30') +