Add 'localtime' to sql history query.
We need to tell sqlite to convert the timestamps to localtime during formatting, otherwise it formats them as though you are in UTC. Also fix up a few uses of mktime.
This commit is contained in:
parent
f45acaa9c8
commit
0eb347186c
@ -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"]),
|
||||
|
@ -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),
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user