Fix a bug in the new news download scheduler code that would cause scheduling based on time of day to not always work (depending on your timezone)

This commit is contained in:
Kovid Goyal 2009-10-20 15:54:54 -06:00
parent dc0a4d9db3
commit a865155f07

View File

@ -230,15 +230,18 @@ class SchedulerConfig(object):
typ, sch, ld = self.un_serialize_schedule(recipe) typ, sch, ld = self.un_serialize_schedule(recipe)
except: except:
return False return False
utcnow = datetime.utcnow()
if typ == 'interval': if typ == 'interval':
return datetime.utcnow() - ld > timedelta(sch) return utcnow - ld > timedelta(sch)
elif typ == 'day/time': elif typ == 'day/time':
day, hour, minute = sch day, hour, minute = sch
now = datetime.now() now = datetime.now()
is_today = day < 0 or day > 6 or \ is_today = day < 0 or day > 6 or \
day == calendar.weekday(now.year, now.month, now.day) day == calendar.weekday(now.year, now.month, now.day)
return is_today and datetime.utcnow().date() != ld.date() and \ is_time = now.hour >= hour and now.minute >= minute
now.hour >= hour and now.minute >= minute was_downloaded_already_today = \
utcnow - ld < timedelta(days=1)
return is_today and not was_downloaded_already_today and is_time
return False return False
def set_account_info(self, urn, un, pw): def set_account_info(self, urn, un, pw):