diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 0f86d0980..e712adcf8 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -251,7 +251,7 @@ def qute_history(url): prev_date = curr_date - one_day # start_time is the last second of curr_date - start_time = time.mktime(next_date.timetuple()) - 1 + start_time = next_date.timestamp() - 1 history = [ (i["url"], i["title"], datetime.datetime.fromtimestamp(i["time"]), diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index 1899c2805..fa8443a60 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -38,9 +38,10 @@ class HistoryCategory(QSqlQueryModel): super().__init__(parent=parent) self.name = "History" - # replace ' to avoid breaking the query - timefmt = "strftime('{}', last_atime, 'unixepoch')".format( - config.get('completion', 'timestamp-format').replace("'", "`")) + # replace ' in timestamp-format to avoid breaking the query + timefmt = ("strftime('{}', last_atime, 'unixepoch', 'localtime')" + .format(config.get('completion', 'timestamp-format') + .replace("'", "`"))) self._query = sql.Query(' '.join([ "SELECT url, title, {}".format(timefmt), diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index f285c1dcc..0b5fcb915 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -20,7 +20,7 @@ """Test the web history completion category.""" import unittest.mock -import time +import datetime import pytest @@ -123,7 +123,7 @@ def test_sorting(max_items, before, after, model_validator, hist, config_stub): """Validate the filtering and sorting results of set_pattern.""" config_stub.data['completion']['web-history-max-items'] = max_items for url, title, atime in before: - timestamp = time.mktime(time.strptime(atime, '%Y-%m-%d')) + timestamp = datetime.datetime.strptime(atime, '%Y-%m-%d').timestamp() hist.insert({'url': url, 'title': title, 'last_atime': timestamp}) cat = histcategory.HistoryCategory() model_validator.set_model(cat)