def lastchange(pyccd_result, ordinal):
    """
    Number of days since last detected change.

    Defaults to 0 in cases where the given ordinal day to calculate from
    is either < 1 or no change was detected before it.

    Args:
        pyccd_result: dict return from pyccd
        ordinal: ordinal day to calculate from

    Returns:
        int
    """
    ret = 0

    if ordinal > 0:
        break_dates = []
        for segment in pyccd_result['change_models']:
            if segment['change_probability'] == 1:
                break_dates.append(segment['break_day'])

        diff = [(ordinal - d) for d in break_dates if (ordinal - d) > 0]

        if diff:
           ret = min(diff)

    return ret