diff --git a/bot/commands/medications.py b/bot/commands/medications.py index b521062..ad52437 100644 --- a/bot/commands/medications.py +++ b/bot/commands/medications.py @@ -25,11 +25,11 @@ def _get_nearest_scheduled_time(times, user_tz=None): # Default to UTC if no timezone provided user_tz = timezone.utc elif isinstance(user_tz, int): - # If user_tz is an offset in minutes, convert to timezone object - # Positive offset means behind UTC, so we need to use Etc/GMT+N - # where N = -offset_minutes/60 (because Etc/GMT+5 means 5 hours behind UTC) - offset_hours = -user_tz // 60 - user_tz = pytz.timezone(f"Etc/GMT+{offset_hours}") + # If user_tz is an offset in minutes, convert to timezone object. + # The int format is: positive = behind UTC (e.g. 480 = UTC-8). + # Python's timezone offset is: positive = ahead of UTC. + # So we negate the input to get the correct standard offset. + user_tz = timezone(timedelta(minutes=-user_tz)) now = datetime.now(user_tz) now_minutes = now.hour * 60 + now.minute