def get_duration(start_dt, end_dt):
    """
    calculate the duration from start_dt to end_dt in seconds

    Raises AssertionError when the duration is negative

    :param start_dt: datetime instance of the start time
    :param end_dt: datetime instance of the end time
    :returns duration in seconds

    """

    duration = (end_dt - start_dt).total_seconds()
    assert duration >= 0, "duration can not be negative (start_dt %s / end_dt %s )" % (start_dt, end_dt)
    return int(duration)