Switch to datetime to calculate postcard timestamps

`mktime()` caused issues with the windows C api
This commit is contained in:
Ben 2020-04-23 17:40:36 +01:00
parent 041146caae
commit 0684a6f908

View File

@ -1,5 +1,6 @@
import time import time
import pytz import pytz
import datetime
from houdini import handlers from houdini import handlers
from houdini.data import db from houdini.data import db
@ -39,10 +40,13 @@ async def handle_get_mail(p):
async for postcard in mail_query.gino.iterate(): async for postcard in mail_query.gino.iterate():
sender_name, sender_id = ('sys', 0) if postcard.sender_id is None else ( sender_name, sender_id = ('sys', 0) if postcard.sender_id is None else (
postcard.parent.safe_nickname(p.server.config.lang), postcard.sender_id) 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())) pst_send_date = postcard.send_date.astimezone(pst)
sent_pst_timestamp = int(time.mktime(sent_pst.timetuple())) pst_send_date = pst_send_date.replace(tzinfo=None)
sent_timestamp += sent_timestamp - sent_pst_timestamp
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}|' postcards.append(f'{sender_name}|{sender_id}|{postcard.postcard_id}|'
f'{postcard.details}|{sent_timestamp+1}|{postcard.id}|{int(postcard.has_read)}') f'{postcard.details}|{sent_timestamp+1}|{postcard.id}|{int(postcard.has_read)}')
await p.send_xt('mg', *postcards) await p.send_xt('mg', *postcards)