def check_textgrid_duration(textgrid,duration):
    """
    Check whether the duration of a textgrid file equals to 'duration'. 
    If not, replace duration of the textgrid file.

    Parameters
    ----------
    textgrid : .TextGrid object
        A .TextGrid object.
    duration : float
        A given length of time.

    Returns
    -------
    textgrid : .TextGrid object
        A modified/unmodified textgrid.

    """
    
    
    endtime = textgrid.tierDict['phones'].entryList[-1].end
    if not endtime==duration:
        last = textgrid.tierDict['phones'].entryList.pop()
        textgrid.tierDict['phones'].entryList.append(last._replace(end=duration))
        
    return textgrid