'Compute the total duration of the given event before the end
of this period, in number of interval
@param event: the S3TimeSeriesEvent
@param interval: the interval expression (string)'

def duration(self, event, interval):

    if ((event.end is None) or (event.end > self.end)):
        end_date = self.end
    else:
        end_date = event.end
    if ((event.start is None) or (event.start >= end_date)):
        result = 0
    else:
        rule = self.get_rule(event.start, end_date, interval)
        if rule:
            result = rule.count()
        else:
            result = 1
    return result
