From 0684a6f90878200ad5bbb98dd1bbe78e52270378 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 23 Apr 2020 17:40:36 +0100 Subject: [PATCH] Switch to datetime to calculate postcard timestamps `mktime()` caused issues with the windows C api --- houdini/handlers/play/mail.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/houdini/handlers/play/mail.py b/houdini/handlers/play/mail.py index c1a35c6..442b0db 100644 --- a/houdini/handlers/play/mail.py +++ b/houdini/handlers/play/mail.py @@ -1,5 +1,6 @@ import time import pytz +import datetime from houdini import handlers from houdini.data import db @@ -39,10 +40,13 @@ async def handle_get_mail(p): async for postcard in mail_query.gino.iterate(): sender_name, sender_id = ('sys', 0) if postcard.sender_id is None else ( postcard.parent.safe_nickname(p.server.config.lang), postcard.sender_id) - sent_pst = postcard.send_date.astimezone(pst) - sent_timestamp = int(time.mktime(postcard.send_date.timetuple())) - sent_pst_timestamp = int(time.mktime(sent_pst.timetuple())) - sent_timestamp += sent_timestamp - sent_pst_timestamp + + pst_send_date = postcard.send_date.astimezone(pst) + pst_send_date = pst_send_date.replace(tzinfo=None) + + offset = datetime.timedelta(seconds=(postcard.send_date - pst_send_date).total_seconds()) + sent_timestamp = int((postcard.send_date + offset).timestamp()) + postcards.append(f'{sender_name}|{sender_id}|{postcard.postcard_id}|' f'{postcard.details}|{sent_timestamp+1}|{postcard.id}|{int(postcard.has_read)}') await p.send_xt('mg', *postcards)