

def timesince(d, now=None):
    '\n    Takes two datetime objects and returns the time between d and now\n    as a nicely formatted string, e.g. "10 minutes".  If d occurs after now,\n    then "0 minutes" is returned.\n\n    Units used are years, months, weeks, days, hours, and minutes.\n    Seconds and microseconds are ignored.  Up to two adjacent units will be\n    displayed.  For example, "2 weeks, 3 days" and "1 year, 3 months" are\n    possible outputs, but "2 weeks, 3 hours" and "1 year, 5 days" are not.\n\n    Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since\n    '
    chunks = (((((60 * 60) * 24) * 365), (lambda n: ungettext('year', 'years', n))), ((((60 * 60) * 24) * 30), (lambda n: ungettext('month', 'months', n))), ((((60 * 60) * 24) * 7), (lambda n: ungettext('week', 'weeks', n))), (((60 * 60) * 24), (lambda n: ungettext('day', 'days', n))), ((60 * 60), (lambda n: ungettext('hour', 'hours', n))), (60, (lambda n: ungettext('minute', 'minutes', n))))
    if (d.__class__ is not datetime.datetime):
        d = datetime.datetime(d.year, d.month, d.day)
    if (not now):
        if d.tzinfo:
            now = datetime.datetime.now(LocalTimezone(d))
        else:
            now = datetime.datetime.now()
    delta = (now - (d - datetime.timedelta(0, 0, d.microsecond)))
    since = ((((delta.days * 24) * 60) * 60) + delta.seconds)
    if (since <= 0):
        return ('0 ' + ugettext('minutes'))
    for (i, (seconds, name)) in enumerate(chunks):
        count = (since // seconds)
        if (count != 0):
            break
    s = (ugettext('%(number)d %(type)s') % {
        'number': count,
        'type': name(count),
    })
    if ((i + 1) < len(chunks)):
        (seconds2, name2) = chunks[(i + 1)]
        count2 = ((since - (seconds * count)) // seconds2)
        if (count2 != 0):
            s += (ugettext(', %(number)d %(type)s') % {
                'number': count2,
                'type': name2(count2),
            })
    return s

dataset/ETHPy150Open dcramer/django-compositepks/django/utils/timesince.py timesince/original