def align_end_hierarchies(hier1, hier2, thres=0.5):
    """Align the end of the hierarchies such that they end at the same exact
    second as long they have the same duration within a certain threshold.

    Parameters
    ----------
    hier1: list
        List containing hierarchical segment boundaries.
    hier2: list
        List containing hierarchical segment boundaries.
    thres: float > 0
        Threshold to decide whether two values are the same.
    """
    dur_h1 = hier1[0][-1]
    for hier in hier1:
        assert hier[-1
            ] == dur_h1, 'hier1 is not correctly formatted {} {}'.format(hier
            [-1], dur_h1)
    dur_h2 = hier2[0][-1]
    for hier in hier2:
        assert hier[-1] == dur_h2, 'hier2 is not correctly formatted'
    if abs(dur_h1 - dur_h2) > thres:
        return
    for hier in hier1:
        hier[-1] = dur_h2
