commit 144eaee28c0b30f3d5023ed7fbf16fd6a9faee05
parent f247ca4c4f7afe925b0e3b1cd02e73cd65840b4f
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Sat, 27 Apr 2024 18:55:23 -0700
Fix timezones for negative UTC offsets
Diffstat:
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/countdown_bot/coreCog.py b/countdown_bot/coreCog.py
@@ -1,6 +1,7 @@
# Import dependencies
import discord
from discord.ext import commands
+from datetime import timedelta
# Import modules
from .botUtilities import COLORS, CommandError, CountdownNotFound, isCountdown, loadCountdown, getContextCountdown, addMessage
@@ -90,7 +91,7 @@ class Core(commands.Cog):
embed.description += f"**Command Prefixes:** `{'`, `'.join(prefixes)}`\n"
cur.execute("CALL getTimezone(%s, null);", (countdown,))
- timezone = cur.fetchone()["_timezone"]
+ timezone = cur.fetchone()["_timezone"].total_seconds() / 3600
if (timezone >= 0):
embed.description += f"**Countdown Timezone:** UTC+{timezone:.2f}\n"
else:
@@ -113,15 +114,16 @@ class Core(commands.Cog):
raise CommandError("Please provide a value for the setting")
elif (key in ["tz", "timezone"]):
try:
- timezone = float(args[0])
+ offset = float(args[0])
+ timezone = timedelta(hours = offset)
except:
raise CommandError(f"Invalid timezone: `{args[0]}`")
else:
cur.execute("CALL setTimezone(%s, %s);", (countdown, timezone))
- if (timezone >= 0):
- embed.description = f"Timezone set to UTC+{timezone:.2f}\n"
+ if (offset >= 0):
+ embed.description = f"Timezone set to UTC+{offset:.2f}\n"
else:
- embed.description = f"Timezone set to UTC-{abs(timezone):.2f}\n"
+ embed.description = f"Timezone set to UTC-{abs(offset):.2f}\n"
elif (key in ["prefix", "prefixes"]):
cur.execute("CALL setPrefixes(%s, %s);", (countdown, list(args)))
embed.description = f"Prefixes updated"
diff --git a/models/dml-core.sql b/models/dml-core.sql
@@ -207,11 +207,11 @@ $$;
-- Get the timezone of a countdown
CREATE PROCEDURE getTimezone (
_countdownID IN BIGINT, -- The countdown channel ID
- _timezone OUT DECIMAL -- The timezone as a UTC offest
+ _timezone OUT INTERVAL -- The timezone as a UTC offest
)
LANGUAGE plpgsql AS $$
BEGIN
- SELECT extract(minute FROM timezone) / 60
+ SELECT timezone
INTO _timezone
FROM countdowns
WHERE countdownID = _countdownID;
@@ -221,13 +221,12 @@ $$;
-- Set the timezone of a countdown
CREATE PROCEDURE setTimezone (
_countdownID IN BIGINT, -- The countdown channel ID
- _timezone IN FLOAT -- The timezone as a UTC offest
+ _timezone IN INTERVAL -- The timezone as a UTC offest
)
LANGUAGE plpgsql AS $$
BEGIN
UPDATE countdowns
- SET timezone = make_interval(0,0,0,0, floor(_timezone)::integer,
- (_timezone * 60)::integer % 60)
+ SET timezone = _timezone
WHERE countdownID = _countdownID;
END
$$;