fix timezone aware issue in playtime calc
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s
All checks were successful
Build and Push Docker Image / build (push) Successful in 12s
This commit is contained in:
parent
2ed97dba5f
commit
a8d4b8259a
@ -8,12 +8,11 @@ from pytz import timezone
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from tortoise import fields
|
from tortoise import fields
|
||||||
from tortoise.functions import Sum
|
from tortoise.models import Model
|
||||||
from tortoise.expressions import F
|
|
||||||
from tortoise.models import Model, Q
|
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
utc = timezone("UTC")
|
||||||
|
|
||||||
|
|
||||||
class SteamProfileSummary(Model):
|
class SteamProfileSummary(Model):
|
||||||
@ -81,7 +80,7 @@ class PlayerSession(Model):
|
|||||||
@property
|
@property
|
||||||
def playtime(self) -> timedelta:
|
def playtime(self) -> timedelta:
|
||||||
if not self.disconnected_at:
|
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
|
return self.disconnected_at - self.connected_at
|
||||||
|
|
||||||
@ -99,8 +98,6 @@ class Player(Model):
|
|||||||
log.info("Getting total playtime for player: %s", self.username)
|
log.info("Getting total playtime for player: %s", self.username)
|
||||||
sessions = await PlayerSession.filter(player=self)
|
sessions = await PlayerSession.filter(player=self)
|
||||||
total_playtime = timedelta()
|
total_playtime = timedelta()
|
||||||
now = datetime.now()
|
|
||||||
utc = timezone("UTC")
|
|
||||||
|
|
||||||
# I know this is terrible efficiency-wise, but the tortoise docs
|
# 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!
|
# are so bad and the annotations don't work like Django's models. Deal with it!
|
||||||
|
Reference in New Issue
Block a user