fix timezone aware issue in playtime calc
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s

This commit is contained in:
Corban-Lee Jones 2024-12-11 23:17:12 +00:00
parent 2ed97dba5f
commit a8d4b8259a

View File

@ -8,12 +8,11 @@ from pytz import timezone
import httpx
from tortoise import fields
from tortoise.functions import Sum
from tortoise.expressions import F
from tortoise.models import Model, Q
from tortoise.models import Model
from discord import Embed
log = logging.getLogger(__name__)
utc = timezone("UTC")
class SteamProfileSummary(Model):
@ -81,7 +80,7 @@ class PlayerSession(Model):
@property
def playtime(self) -> timedelta:
if not self.disconnected_at:
return datetime.now() - self.connected_at
return datetime.now(tz=utc) - self.connected_at
return self.disconnected_at - self.connected_at
@ -99,8 +98,6 @@ class Player(Model):
log.info("Getting total playtime for player: %s", self.username)
sessions = await PlayerSession.filter(player=self)
total_playtime = timedelta()
now = datetime.now()
utc = timezone("UTC")
# I know this is terrible efficiency-wise, but the tortoise docs
# are so bad and the annotations don't work like Django's models. Deal with it!