human
Complete this python program:
def datestr(then, now=None):
assistant
#Here is the Python code you requested.

    """Converts a (UTC) datetime object to a nice string representation.
    >>> from datetime import datetime, timedelta
    >>> d = datetime(1970, 5, 1)
    >>> datestr(d, now=d)
    \0 microseconds ago\
    >>> for t, v in {
    ...   timedelta(microseconds=1): \1 microsecond ago\,
    ...   timedelta(microseconds=2): \2 microseconds ago\,
    ...   -timedelta(microseconds=1): \1 microsecond from now\,
    ...   -timedelta(microseconds=2): \2 microseconds from now\,
    ...   timedelta(microseconds=2000): \2 milliseconds ago\,
    ...   timedelta(seconds=2): \2 seconds ago\,
    ...   timedelta(seconds=2*60): \2 minutes ago\,
    ...   timedelta(seconds=2*60*60): \2 hours ago\,
    ...   timedelta(days=2): \2 days ago\,
    ... }.iteritems():
    ...     assert datestr(d, now=d+t) == v
    >>> datestr(datetime(1970, 1, 1), now=d)
    \January  1\
    >>> datestr(datetime(1969, 1, 1), now=d)
    \January  1, 1969\
    >>> datestr(datetime(1970, 6, 1), now=d)
    \June  1, 1970\
    >>> datestr(None)
    """
    def agohence(n, what, divisor=None):
        if divisor:
            n = (n // divisor)
        out = ((str(abs(n)) + '    ') + what)
        if (abs(n) != 1):
            out += 's'
        out += '    '
        if (n < 0):
            out += 'from    now'
        else:
            out += 'ago'
        return out
    oneday = ((24 * 60) * 60)
    if (not then):
        return ''
    if (not now):
        now = datetime.datetime.utcnow()
    if (type(now).__name__ == 'DateTime'):
        now = datetime.datetime.fromtimestamp(now)
    if (type(then).__name__ == 'DateTime'):
        then = datetime.datetime.fromtimestamp(then)
    elif (type(then).__name__ == 'date'):
        then = datetime.datetime(then.year, then.month, then.day)
    delta = (now - then)
    deltaseconds = int((((delta.days * oneday) + delta.seconds) + (delta.microseconds * 1e-06)))
    deltadays = (abs(deltaseconds) // oneday)
    if (deltaseconds < 0):
        deltadays *= (-1)
    if deltadays:
        if (abs(deltadays) < 4):
            return agohence(deltadays, 'day')
        try:
            out = then.strftime('%B    %e')
        except ValueError:
            out = then.strftime('%B    %d')
        if ((then.year != now.year) or (deltadays < 0)):
            out += (',    %s' % then.year)
        return out
    if int(deltaseconds):
        if (abs(deltaseconds) > (60 * 60)):
            return agohence(deltaseconds, 'hour', (60 * 60))
        elif (abs(deltaseconds) > 60):
            return agohence(deltaseconds, 'minute', 60)
        else:
            return agohence(deltaseconds, 'second')
    deltamicroseconds = delta.microseconds
    if delta.days:
        deltamicroseconds = int((delta.microseconds - 1000000.0))
    if (abs(deltamicroseconds) > 1000):
        return agohence(deltamicroseconds, 'millisecond', 1000)
    return agohence(deltamicroseconds, 'microsecond')