def timesince(d, now):
def pluralize(a, b):<EOL><INDENT>def inner(n):<EOL><INDENT>if n == <NUM_LIT:1>:<EOL><INDENT>return a % n<EOL><DEDENT>return b % n<EOL><DEDENT>return inner<EOL><DEDENT>def ugettext(s):<EOL><INDENT>return s<EOL><DEDENT>chunks = (<EOL>(<NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:30>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:7>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT> * <NUM_LIT> * <NUM_LIT>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT> * <NUM_LIT>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT>, pluralize('<STR_LIT>', '<STR_LIT>')),<EOL>(<NUM_LIT:0>, pluralize('<STR_LIT>', '<STR_LIT>'))<EOL>)<EOL>if not isinstance(d, datetime.datetime):<EOL><INDENT>d = datetime.datetime(d.year, d.month, d.day)<EOL><DEDENT>if now and not isinstance(now, datetime.datetime):<EOL><INDENT>now = datetime.datetime(now.year, now.month, now.day)<EOL><DEDENT>delta = now - d<EOL>since = delta.days * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> + delta.seconds<EOL>if since <= <NUM_LIT:0>:<EOL><INDENT>_, name = chunks[-<NUM_LIT:1>]<EOL>return name(<NUM_LIT:0>)<EOL><DEDENT>for i, (seconds, name) in enumerate(chunks):<EOL><INDENT>if seconds > <NUM_LIT:0>:<EOL><INDENT>count = since // seconds<EOL>if count != <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>count = since<EOL><DEDENT><DEDENT>result = name(count)<EOL>if i + <NUM_LIT:1> < len(chunks):<EOL><INDENT>seconds2, name2 = chunks[i + <NUM_LIT:1>]<EOL>if seconds2 > <NUM_LIT:0>:<EOL><INDENT>count2 = (since - (seconds * count)) // seconds2<EOL><DEDENT>else:<EOL><INDENT>count2 = since - (seconds * count)<EOL><DEDENT>if count2 != <NUM_LIT:0>:<EOL><INDENT>result += ugettext('<STR_LIT:U+002CU+0020>') + name2(count2)<EOL><DEDENT><DEDENT>return result<EOL>
Taken from django.utils.timesince and modified to simpler requirements.

Takes two datetime objects and returns the time between d and now
as a nicely formatted string, e.g. "10 minutes". If d occurs after now,
then "0 minutes" is returned.

Units used are years, months, weeks, days, hours, and minutes.
Seconds and microseconds are ignored. Up to two adjacent units will be
displayed. For example, "2 weeks, 3 days" and "1 year, 3 months" are
possible outputs, but "2 weeks, 3 hours" and "1 year, 5 days" are not.

Adapted from
http://web.archive.org/web/20060617175230/\
http://blog.natbat.co.uk/archive/2003/Jun/14/time_since