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.

def pretty_date(ugly_time=False, ln=None):
    """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.
    """

    ln = default_ln(ln)
    _ = gettext_set_language(ln)

    now = real_datetime.now()

    if isinstance(ugly_time, six.string_types):
        # try to convert it to epoch timestamp
        date_format = '%Y-%m-%d %H:%M:%S.%f'
        try:
            ugly_time = time.strptime(ugly_time, date_format)
            ugly_time = int(time.mktime(ugly_time))
        except ValueError:
            # doesn't match format, let's try to guess
            try:
                ugly_time = int(guess_datetime(ugly_time))
            except ValueError:
                return ugly_time
            ugly_time = int(time.mktime(ugly_time))

    # Initialize the time period difference
    if isinstance(ugly_time, int):
        diff = now - real_datetime.fromtimestamp(ugly_time)
    elif isinstance(ugly_time, real_datetime):
        diff = now - ugly_time
    elif not ugly_time:
        diff = now - now
    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:
        if day_diff / 7 == 7:
            return _("Last week")
        else:
            return str(day_diff / 7) + _(" weeks ago")
    if day_diff < 365:
        if day_diff / 30 == 1:
            return _("Last month")
        else:
            return str(day_diff / 30) + _(" months ago")
    if day_diff / 365 == 1:
        return _("Last year")
    else:
        return str(day_diff / 365) + _(" years ago")