Skip to content

Commit

Permalink
Fix handling of timezones
Browse files Browse the repository at this point in the history
It's always better to do calculations in UTC.
Create a UTC "now", create a tz-aware "at" time,
then rely on pytz to handle the time difference across timezones.
  • Loading branch information
Alan Huang authored and Alan Huang committed Jan 1, 2019
1 parent 02c59ec commit 2f7b5cc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sopel/modules/remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ def at(bot, trigger):
timezone = 'UTC'

pytz_timezone = pytz.timezone(timezone)
now = pytz_timezone.localize(datetime.now())
now = pytz.utc.localize(datetime.utcnow())
at_time = datetime(year, month, day,
int(hour), int(minute), int(second))
at_time = pytz_timezone.localize(at_time)
timediff = pytz_timezone.normalize(at_time) - now
timediff = at_time - now
else:
if tz and tz.upper() != 'UTC':
bot.reply("I don't have timezone support installed.")
return NOLIMIT
now = datetime.now()
now = datetime.utcnow()
at_time = datetime(year, month, day,
int(hour), int(minute), int(second))
timediff = at_time - now
Expand Down

0 comments on commit 2f7b5cc

Please sign in to comment.