Fix QDateTime conversions

- Qt 5.7 doesn't have QDateTime::(from|to)SecsSinceEpoch, so we need to use the
  msecs variant instead.
- We were passing a float which causes a TypeError (rather than being truncated
  to an int) with newer PyQt versions.
This commit is contained in:
Florian Bruhin 2020-07-29 17:42:22 +02:00
parent f8e83dcaa1
commit 9bdcea42de
2 changed files with 4 additions and 3 deletions

View File

@ -223,10 +223,10 @@ def _qdatetime_to_completion_format(qdate):
if not qdate.isValid():
ts = 0
else:
ts = qdate.toSecsSinceEpoch()
ts = qdate.toMSecsSinceEpoch()
if ts < 0:
ts = 0
pydate = datetime.datetime.fromtimestamp(ts)
pydate = datetime.datetime.fromtimestamp(ts / 1000)
return pydate.strftime(config.val.completion.timestamp_format)

View File

@ -1211,7 +1211,8 @@ def tab_with_history(fake_web_tab, tabbed_browser_stubs, info, monkeypatch):
entry = mock.Mock(spec=QWebEngineHistoryItem)
entry.url.return_value = QUrl(url)
entry.title.return_value = title
entry.lastVisited.return_value = QDateTime.fromSecsSinceEpoch(ts)
dt = QDateTime.fromMSecsSinceEpoch(int(ts * 1000))
entry.lastVisited.return_value = dt
history.append(entry)
tab.history._history = mock.Mock(spec=QWebEngineHistory)
tab.history._history.items.return_value = history