(start, end, round_up_after=2)
Return an approximate human readable time difference between two dates.

    Parameters
    ----------
    start : int
        Unix timestamp
    end : int
        Unix timestamp
    round_up_after : int
        The number of time units before we round up to the next, larger time
        unit e.g. setting to 2 will allow up to 2 days worth of hours to be
        shown, after that the difference is shown in days. Or put another way
        we will show from 1-48 hours before switching to days.

    Returns
    -------
    str
Return an approximate human readable time difference between two dates.
Return an approximate human readable time difference between two dates .
def format_time_diff(start, end, round_up_after=2):
    """Return an approximate human readable time difference between two dates.

    Parameters
    ----------
    start : int
        Unix timestamp
    end : int
        Unix timestamp
    round_up_after : int
        The number of time units before we round up to the next, larger time
        unit e.g. setting to 2 will allow up to 2 days worth of hours to be
        shown, after that the difference is shown in days. Or put another way
        we will show from 1-48 hours before switching to days.

    Returns
    -------
    str

    """
    start = utc_from_timestamp(start)
    end = utc_from_timestamp(end)
    diff = abs(end - start)  # type: datetime.timedelta

    # Get the different resolutions
    seconds = diff.total_seconds()
    minutes = seconds // 60
    hours = minutes // 60
    days = diff.days
    weeks = days // 7
    months = (end.year - start.year) * 12 + end.month - start.month
    years = months // 12

    # Check which resolution is most appropriate
    if years >= round_up_after:
        return '~%d years' % years
    elif months >= round_up_after:
        return '~%d months' % months
    elif weeks >= round_up_after:
        return '~%d weeks' % weeks
    elif days >= round_up_after:
        return '~%d days' % days
    elif hours >= round_up_after:
        return '~%d hours' % hours
    elif minutes >= round_up_after:
        return '~%d minutes' % minutes
    else:
        return '%d seconds' % seconds
def format_time_diff ( start , end , round_up_after = 2 ) : start = utc_from_timestamp ( start ) end = utc_from_timestamp ( end ) diff = abs ( end - start ) # type: datetime.timedelta # Get the different resolutions seconds = diff . total_seconds ( ) minutes = seconds // 60 hours = minutes // 60 days = diff . days weeks = days // 7 months = ( end . year - start . year ) * 12 + end . month - start . month years = months // 12 # Check which resolution is most appropriate if years >= round_up_after : return '~%d years' % years elif months >= round_up_after : return '~%d months' % months elif weeks >= round_up_after : return '~%d weeks' % weeks elif days >= round_up_after : return '~%d days' % days elif hours >= round_up_after : return '~%d hours' % hours elif minutes >= round_up_after : return '~%d minutes' % minutes else : return '%d seconds' % seconds