diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 0e05cd7fb..0f86d0980 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -192,6 +192,8 @@ def history_data(start_time, offset=None): start_time: select history starting from this timestamp. offset: number of items to skip """ + # history atimes are stored as ints, ensure start_time is not a float + start_time = int(start_time) hist = objreg.get('web-history') if offset is not None: entries = hist.entries_before(start_time, limit=1000, offset=offset) @@ -200,7 +202,7 @@ def history_data(start_time, offset=None): end_time = start_time - 24*60*60 entries = hist.entries_between(end_time, start_time) - return [{"url": e.url, "title": e.title or e.url, "time": e.atime * 1000} + return [{"url": e.url, "title": e.title or e.url, "time": e.atime} for e in entries] @@ -252,7 +254,7 @@ def qute_history(url): start_time = time.mktime(next_date.timetuple()) - 1 history = [ (i["url"], i["title"], - datetime.datetime.fromtimestamp(i["time"]/1000), + datetime.datetime.fromtimestamp(i["time"]), QUrl(i["url"]).host()) for i in history_data(start_time) ] diff --git a/qutebrowser/javascript/history.js b/qutebrowser/javascript/history.js index 3f5f9def6..26b4405e9 100644 --- a/qutebrowser/javascript/history.js +++ b/qutebrowser/javascript/history.js @@ -174,7 +174,8 @@ window.loadHistory = (function() { for (var i = 0, len = history.length; i < len; i++) { var item = history[i]; - var currentItemDate = new Date(item.time); + // python's time.time returns seconds, but js Date expects ms + var currentItemDate = new Date(item.time * 1000); getSessionNode(currentItemDate).appendChild(makeHistoryRow( item.url, item.title, currentItemDate.toLocaleTimeString() )); diff --git a/tests/unit/browser/test_qutescheme.py b/tests/unit/browser/test_qutescheme.py index 154af0355..693b2607c 100644 --- a/tests/unit/browser/test_qutescheme.py +++ b/tests/unit/browser/test_qutescheme.py @@ -129,8 +129,8 @@ class TestHistoryHandler: # test times end_time = start_time - 24*60*60 for item in items: - assert item['time'] <= start_time * 1000 - assert item['time'] > end_time * 1000 + assert item['time'] <= start_time + assert item['time'] > end_time def test_qute_history_benchmark(self, fake_web_history, benchmark, now): r = range(100000)