def get_next_valid_time_from_t(self, timestamp):
        timestamp = int(timestamp)
        original_t = timestamp
        res_from_cache = self.find_next_valid_time_from_cache(timestamp)
        if res_from_cache is not None:
            return res_from_cache
        still_loop = True
        while still_loop:
            local_min = None
            dr_mins = []
            for daterange in self.dateranges:
                dr_mins.append(daterange.get_next_valid_time_from_t(timestamp))
            s_dr_mins = sorted([d for d in dr_mins if d is not None])
            for t01 in s_dr_mins:
                if not self.exclude and still_loop:
                    local_min = t01
                    still_loop = False
                else:
                    for timeperiod in self.exclude:
                        if not timeperiod.is_time_valid(t01) and still_loop:
                            local_min = t01
                            still_loop = False
            if local_min is None:
                exc_mins = []
                if s_dr_mins != []:
                    for timeperiod in self.exclude:
                        exc_mins.append(timeperiod.get_next_invalid_time_from_t(s_dr_mins[0]))
                s_exc_mins = sorted([d for d in exc_mins if d is not None])
                if s_exc_mins != []:
                    local_min = s_exc_mins[0]
            if local_min is None:
                still_loop = False
            else:
                timestamp = local_min
                if timestamp > original_t + 3600 * 24 * 366 + 1:
                    still_loop = False
                    local_min = None
        self.cache[original_t] = local_min
        return local_min