示例#1
0
def time_in_range(time, time_dictionary):
    """time_dictionary will be of the format:
    {
        '*': [(begin_hour, end_hour), (begin_hour, end_hour), ...] catch all for days
        1: [(begin_hour, end_hour), ...] hours for Monday (Monday 1, Sunday 7)
    }
    All times UTC
    """

    if not time_dictionary:
        return True

    hours_for_today = time_dictionary.get(time.isoweekday())
    if not hours_for_today:
        hours_for_today = time_dictionary.get('*')

    for valid_hours in hours_for_today:
        if valid_hours[0] <= time.hour <= valid_hours[1]:
            return True

    return False
示例#2
0
def time_in_range(time, time_dictionary):
    """time_dictionary will be of the format:
    {
        '*': [(begin_hour, end_hour), (begin_hour, end_hour), ...] catch all for days
        1: [(begin_hour, end_hour), ...] hours for Monday (Monday 1, Sunday 7)
    }
    All times UTC
    """

    if not time_dictionary:
        return True

    hours_for_today = time_dictionary.get(time.isoweekday())
    if not hours_for_today:
        hours_for_today = time_dictionary.get('*')

    for valid_hours in hours_for_today:
        if valid_hours[0] <= time.hour <= valid_hours[1]:
            return True

    return False
示例#3
0
def is_restricted(w, time):
	ti_zone = tz.tzlocal()
	time = time.replace(tzinfo=ti_zone)

	day = time.isoweekday()
	hour = time.time()
	
	# restriction_on_days == False mean no restriction for the day
	restriction_on_days = False

	rt = RestrictionTime.objects.get(id=w.restriction_time_id)
	rd = RestrictionDay.objects.get(id=rt.days_id)

	if day == 1:
		if rd.monday:
			restriction_on_days = True
	elif day == 2:
		if rd.tuesday:
			restriction_on_days = True
	elif day == 3:
		if rd.wednesday:
			restriction_on_days = True
	elif day == 4:
		if rd.thursday:
			restriction_on_days = True
	elif day == 5:
		if rd.friday:
			restriction_on_days = True
	elif day == 6:
		if rd.saterday:
			restriction_on_days = True
	elif day == 7:
		if rd.sunday:
			restriction_on_days = True

	if restriction_on_days:
		return ((rt.start <= hour) and (hour < rt.end))
	else:
		return False
def getWeekStarts(time):
    # CDN stores weeks starting on mondays
    day = time.isoweekday()
    return time - timedelta(day-1)
示例#5
0
 def trigger(self, time):
     nows = [time.isoweekday(),time.month, time.day, time.hour, time.minute]
     nows.reverse()
     result = [n in t for (n,t) in zip(nows,self.triggers)]
     return all(result)