def human_timestamp(__timestamp: datetime.datetime) -> str:
    """Format a relative time.

    Args:
        __timestamp: Event to generate relative timestamp against
    Returns:
        Human readable date and time offset
    """
    numstr = '. a two three four five six seven eight nine ten'.split()

    matches = [
        60 * 60 * 24 * 365,
        60 * 60 * 24 * 28,
        60 * 60 * 24 * 7,
        60 * 60 * 24,
        60 * 60,
        60,
        1,
    ]
    match_names = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']

    if __timestamp.tzinfo is None:
        __timestamp = __timestamp.replace(tzinfo=datetime.timezone.utc)

    now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)

    delta = int((now - __timestamp).total_seconds())
    for scale in matches:
        i = delta // scale
        if i:
            name = match_names[matches.index(scale)]
            break
    else:
        i = 0  # Too small

    if i == 0:
        result = 'right now'
    elif i == 1 and name in ('year', 'month', 'week'):
        result = 'last {}'.format(name)
    elif i == 1 and name == 'day':
        result = 'yesterday'
    elif i == 1 and name == 'hour':
        result = 'about an hour ago'
    else:
        result = 'about {} {}{} ago'.format(i if i > 10 else numstr[i], name,
                                            's' if i > 1 else '')
    return result
def human_timestamp ( __timestamp : datetime . datetime ) -> str : numstr = '. a two three four five six seven eight nine ten' . split ( ) matches = [ 60 * 60 * 24 * 365 , 60 * 60 * 24 * 28 , 60 * 60 * 24 * 7 , 60 * 60 * 24 , 60 * 60 , 60 , 1 , ] match_names = [ 'year' , 'month' , 'week' , 'day' , 'hour' , 'minute' , 'second' ] if __timestamp . tzinfo is None : __timestamp = __timestamp . replace ( tzinfo = datetime . timezone . utc ) now = datetime . datetime . utcnow ( ) . replace ( tzinfo = datetime . timezone . utc ) delta = int ( ( now - __timestamp ) . total_seconds ( ) ) for scale in matches : i = delta // scale if i : name = match_names [ matches . index ( scale ) ] break else : i = 0 if i == 0 : result = 'right now' elif i == 1 and name in ( 'year' , 'month' , 'week' ) : result = 'last {}' . format ( name ) elif i == 1 and name == 'day' : result = 'yesterday' elif i == 1 and name == 'hour' : result = 'about an hour ago' else : result = 'about {} {}{} ago' . format ( i if i > 10 else numstr [ i ] , name , 's' if i > 1 else '' ) return result
Format a relative time.

    Args:
        __timestamp: Event to generate relative timestamp against
    Returns:
        Human readable date and time offset