Skip to content

Commit acfe078

Browse files
committed
UTC fixes
1 parent eab9537 commit acfe078

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

plugins/greenieboard/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ async def prune(self, conn: psycopg.AsyncConnection, *, days: int = -1, ucids: l
129129
for ucid in ucids:
130130
await conn.execute('DELETE FROM traps WHERE player_ucid = %s', (ucid,))
131131
elif days > -1:
132-
await conn.execute("DELETE FROM traps WHERE time < (DATE(NOW()) - %s::interval)", (f'{days} days', ))
132+
await conn.execute("""
133+
DELETE FROM traps WHERE time < (DATE(NOW() AT TIME ZONE 'UTC') - %s::interval)
134+
""",(f'{days} days', ))
133135
self.log.debug('Greenieboard pruned.')
134136

135137
async def update_ucid(self, conn: psycopg.AsyncConnection, old_ucid: str, new_ucid: str) -> None:

plugins/mission/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,10 +1622,10 @@ async def send_token(token: str):
16221622
token = str(random.randrange(1000, 9999))
16231623
await cursor.execute("""
16241624
INSERT INTO players (ucid, discord_id, last_seen)
1625-
VALUES (%s, %s, NOW())
1625+
VALUES (%s, %s, NOW() AT TIME ZONE 'UTC')
16261626
""", (token, interaction.user.id))
16271627
break
1628-
except psycopg.DatabaseError:
1628+
except psycopg.errors.UniqueViolation:
16291629
pass
16301630
await send_token(token)
16311631

plugins/serverstats/serverstats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ async def render(self, server_name: Optional[str], interval: Optional[str] = "1
379379
SELECT
380380
s.player_ucid,
381381
COUNT(DISTINCT DATE(s.hop_on)) AS days_present,
382-
CASE WHEN f.first_seen >= NOW() - INTERVAL '{interval}' THEN true ELSE false END AS is_new
382+
CASE WHEN f.first_seen >= (NOW() AT TIME ZONE 'UTC') - INTERVAL '{interval}' THEN true ELSE false END AS is_new
383383
FROM
384384
statistics s
385385
LEFT JOIN missions m ON s.mission_id = m.id
@@ -398,7 +398,7 @@ async def render(self, server_name: Optional[str], interval: Optional[str] = "1
398398
),
399399
date_series AS (
400400
SELECT generate_series(1, (
401-
SELECT DATE_PART('day', NOW() - (NOW() - INTERVAL '{interval}'))::INTEGER)
401+
SELECT DATE_PART('day', (NOW() AT TIME ZONE 'UTC') - ((NOW() AT TIME ZONE 'UTC') - INTERVAL '{interval}'))::INTEGER)
402402
) AS date
403403
)
404404
SELECT

0 commit comments

Comments
 (0)