# Buggy code
def pretty_date(time=False):
    """
    Get a datetime object or a int() Epoch timestamp and return a
    pretty string like 'an hour ago', 'Yesterday', '3 months ago',
    'just now', etc
    """
    now = datetime.now()
    if isinstance(time, int):
        diff = now - datetime.fromtimestamp(time)
    elif isinstance(time, datetime):
        diff = now - time
    elif not time:
        diff = timedelta(0)
    second_diff = diff.seconds
    day_diff = diff.days

    if day_diff < 0:
        return ""

    if day_diff == 0:
        if second_diff < 10:
            return "just now"
        if second_diff < 60:
            return str(second_diff) + " seconds ago"
        if second_diff < 120:
            return "a minute ago"
        if second_diff < 3600:
            return str(second_diff // 60) + " minutes ago"
        if second_diff < 7200:
            return "an hour ago"
        if second_diff < 86400:
            return str(second_diff // 3600) + " hours ago"
    if day_diff == 1:
        return "yesterday"
    if day_diff < 7:
        return str(day_diff) + " days ago"
    if day_diff < 31:
        weeks = day_diff // 7
        word = "week" if weeks == 1 else "weeks"
        return str(weeks) + " " + word + " ago"
    if day_diff < 365:
        months = day_diff // 30
        word = "month" if months == 1 else "months"
        return str(months) + " " + word + " ago"

    years = day_diff // 365
    word = "year" if years == 1 else "years"
    return str(years) + " " + word + " ago"


# Traceback (UnboundLocalError)
INFO:Executor:Executing code with task id: 6f1c8ce3c6
ERROR   1551721422.95            tribler_window:67   (root)  Traceback (most recent call last):
File "TriblerGUI\widgets\tablecontentmodel.py", line 91, in data
File "TriblerGUI\widgets\tablecontentmodel.py", line 145, in <lambda>
File "TriblerGUI\utilities.py", line 99, in pretty_date
UnboundLocalError: local variable 'diff' referenced before assignment

# Fixed code
def pretty_date(time=False):
    """
    Get a datetime object or a int() Epoch timestamp and return a
    pretty string like 'an hour ago', 'Yesterday', '3 months ago',
    'just now', etc
    """
    now = datetime.now()
    if isinstance(time, integer_types):
        diff = now - datetime.fromtimestamp(time)
    elif isinstance(time, datetime):
        diff = now - time
    elif not time:
        diff = timedelta(0)
    second_diff = diff.seconds
    day_diff = diff.days

    if day_diff < 0:
        return ""

    if day_diff == 0:
        if second_diff < 10:
            return "just now"
        if second_diff < 60:
            return str(second_diff) + " seconds ago"
        if second_diff < 120:
            return "a minute ago"
        if second_diff < 3600:
            return str(second_diff // 60) + " minutes ago"
        if second_diff < 7200:
            return "an hour ago"
        if second_diff < 86400:
            return str(second_diff // 3600) + " hours ago"
    if day_diff == 1:
        return "yesterday"
    if day_diff < 7:
        return str(day_diff) + " days ago"
    if day_diff < 31:
        weeks = day_diff // 7
        word = "week" if weeks == 1 else "weeks"
        return str(weeks) + " " + word + " ago"
    if day_diff < 365:
        months = day_diff // 30
        word = "month" if months == 1 else "months"
        return str(months) + " " + word + " ago"

    years = day_diff // 365
    word = "year" if years == 1 else "years"
    return str(years) + " " + word + " ago"