Fix remind

This commit is contained in:
dpedu 2015-06-23 00:12:37 -07:00
parent e49f831891
commit 658059bbad
1 changed files with 24 additions and 12 deletions

View File

@ -130,27 +130,38 @@ class Remind(ModuleBase):
second = int(second) second = int(second)
except: except:
self.bot.act_PRIVMSG(replyTo, "%s: .at - Remind at a time. Example: .at 20:45EST Do your homework!", prefixObj.nick) self.bot.act_PRIVMSG(replyTo, "%s: .at - Remind at a time. Example: .at 20:45EST Do your homework!" % prefixObj.nick)
return return
now = datetime.now() now = datetime.now()
remindAt = datetime.now()
remindAt = datetime.now().replace(hour=hour).replace(minute=minute).replace(microsecond=0) # if there was timezone, make sure the time we're reminding them at is relative to their timezone
if second == None:
remindAt = remindAt.replace(second=0)
else:
remindAt = remindAt.replace(second=second)
# if there was timezone, adjust for it
if not tz == None: if not tz == None:
try: try:
theirzone = pytz.timezone(Remind.translateZoneStr(tz)) theirzone = pytz.timezone(Remind.translateZoneStr(tz))
except: except:
self.bot.act_PRIVMSG(replyTo, "%s: I don't recognize the timezone '%s'." % (prefixObj.nick, tz)) self.bot.act_PRIVMSG(replyTo, "%s: I don't recognize the timezone '%s'." % (prefixObj.nick, tz))
return return
theirtime = theirzone.localize(remindAt, is_dst=Remind.is_dst(theirzone)) remindAt = theirzone.localize(remindAt, is_dst=Remind.is_dst(theirzone))
remindAt = theirtime.astimezone(pytz.timezone(self.config["mytimezone"])).replace(tzinfo=None)
# Set the hour and minute we'll remind them at today. If the ends up being in the past, we'll add a day alter
remindAt = remindAt.replace(hour=hour).replace(minute=minute).replace(microsecond=0)
# Set seconds
if second == None:
remindAt = remindAt.replace(second=0)
else:
remindAt = remindAt.replace(second=second)
# if there was timezone, convert remindAt to our zone
if not tz == None:
try:
theirzone = pytz.timezone(Remind.translateZoneStr(tz))
except:
self.bot.act_PRIVMSG(replyTo, "%s: I don't recognize the timezone '%s'." % (prefixObj.nick, tz))
return
remindAt = remindAt.astimezone(pytz.timezone(self.config["mytimezone"])).replace(tzinfo=None)
# Advance it a day if the time would have been earlier today # Advance it a day if the time would have been earlier today
while remindAt<now: while remindAt<now:
@ -182,7 +193,8 @@ class Remind(ModuleBase):
@staticmethod @staticmethod
def translateZoneStr(zonestr): def translateZoneStr(zonestr):
translations = { translations = {
"EDT":"US/Eastern" "EDT":"US/Eastern",
"PDT":"America/Los_Angeles"
} }
if zonestr in translations: if zonestr in translations:
return translations[zonestr] return translations[zonestr]