<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def getTimeOfClassesRemaining(self,numClasses=0):
        '''
        For checking things like prerequisites, it's useful to check if a requirement is 'almost' met
        '''
        occurrences = EventOccurrence.objects.filter(
            cancelled=False,
            event__in=[x.event for x in self.temporaryeventregistration_set.filter(event__series__isnull=False)],
        ).order_by('-endTime')
        if occurrences.count() > numClasses:
            return occurrences[numClasses].endTime
        else:
            return occurrences.last().startTime