def get_num_missed_windows(case): """ Get the number of reminder events that were missed on registration day. """ domain_obj = Domain.get_by_name(case.domain, strict=True) # unlike in most other projects, case.opened_on is actually in UTC # because it was submitted from cloudcare opened_timestamp = PhoneTime(case.opened_on, pytz.UTC).user_time(domain_obj.get_default_timezone()).done() day_of_week = opened_timestamp.weekday() time_of_day = opened_timestamp.time() # In order to use timedelta, we need a datetime current_time = datetime.combine(date(2000, 1, 1), time_of_day) window_time = datetime.combine(date(2000, 1, 1), WINDOWS[day_of_week][0]) if current_time < window_time: return 0 window_interval = (WINDOWS[day_of_week][1] - 60) / 5 for i in range(1, 5): window_time += timedelta(minutes=window_interval) if current_time < window_time: return i return 5