summaryrefslogtreecommitdiff
path: root/poezio/mam.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2020-05-22 17:13:11 +0200
committermathieui <mathieui@mathieui.net>2020-05-23 16:13:44 +0200
commit4210f5c776dab2439cecb1e19dc3997109cab400 (patch)
tree847060410690cf0da16fe6c6bd95aec0ab49e07d /poezio/mam.py
parent29eef159d50c836fbd7a27770775d63700dc7f19 (diff)
downloadpoezio-4210f5c776dab2439cecb1e19dc3997109cab400.tar.gz
poezio-4210f5c776dab2439cecb1e19dc3997109cab400.tar.bz2
poezio-4210f5c776dab2439cecb1e19dc3997109cab400.tar.xz
poezio-4210f5c776dab2439cecb1e19dc3997109cab400.zip
Convert all datetimes to UTC when doing comparisons
Diffstat (limited to 'poezio/mam.py')
-rw-r--r--poezio/mam.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/poezio/mam.py b/poezio/mam.py
index ee5b1be8..4171de5e 100644
--- a/poezio/mam.py
+++ b/poezio/mam.py
@@ -25,6 +25,7 @@ from poezio.theming import get_theme
from poezio import tabs
from poezio import xhtml, colors
from poezio.config import config
+from poezio.common import to_utc
from poezio.text_buffer import TextBuffer, HistoryGap
from poezio.ui.types import (
BaseMessage,
@@ -89,7 +90,6 @@ def make_line(
user=None,
)
-
async def get_mam_iterator(
core,
groupchat: bool,
@@ -181,14 +181,11 @@ async def fetch_history(tab: tabs.Tab,
break
if end is None:
end = datetime.now()
- tzone = datetime.now().astimezone().tzinfo
- end = end.replace(tzinfo=tzone).astimezone(tz=timezone.utc)
- end = end.replace(tzinfo=None)
+ end = to_utc(end)
end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
if start is not None:
- start = start.replace(tzinfo=tzone).astimezone(tz=timezone.utc)
- start = start.replace(tzinfo=None)
+ start = to_utc(start)
start = datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
mam_iterator = await get_mam_iterator(
@@ -224,7 +221,7 @@ async def on_new_tab_open(tab: tabs.Tab) -> None:
amount = 2 * tab.text_win.height
end = datetime.now()
for message in tab._text_buffer.messages:
- if isinstance(message, Message) and message.time < end:
+ if isinstance(message, Message) and to_utc(message.time) < to_utc(end):
end = message.time
break
end = end - timedelta(microseconds=1)