def naturaldelta(value, months=True):
    """Given a timedelta or a number of seconds, return a natural
    representation of the amount of time elapsed.  This is similar to
    ``naturaltime``, but does not add tense to the result.  If ``months``
    is True, then a number of months (based on 30.5 days) will be used
    for fuzziness between years."""
    now = _now()
    date, delta = date_and_delta(value)
    if date is None:
        return value

    use_months = months

    seconds = abs(delta.seconds)
    days = abs(delta.days)
    years = days // 365
    days = days % 365
    months = int(days // 30.5)

    if not years and days < 1:
        if seconds == 0:
            return _("a moment")
        elif seconds == 1:
            return _("a second")
        elif seconds < 60:
            return ngettext("%d second", "%d seconds", seconds) % seconds
        elif 60 <= seconds < 120:
            return _("a minute")
        elif 120 <= seconds < 3600:
            minutes = seconds // 60
            return ngettext("%d minute", "%d minutes", minutes) % minutes
        elif 3600 <= seconds < 3600 * 2:
            return _("an hour")
        elif 3600 < seconds:
            hours = seconds // 3600
            return ngettext("%d hour", "%d hours", hours) % hours
    elif years == 0:
        if days == 1:
            return _("a day")
        if not use_months:
            return ngettext("%d day", "%d days", days) % days
        else:
            if not months:
                return ngettext("%d day", "%d days", days) % days
            elif months == 1:
                return _("a month")
            else:
                return ngettext("%d month", "%d months", months) % months
    elif years == 1:
        if not months and not days:
            return _("a year")
        elif not months:
            return ngettext("1 year, %d day", "1 year, %d days", days) % days
        elif use_months:
            if months == 1:
                return _("1 year, 1 month")
            else:
                return ngettext("1 year, %d month",
                                "1 year, %d months", months) % months
        else:
            return ngettext("1 year, %d day", "1 year, %d days", days) % days
    else:
        return ngettext("%d year", "%d years", years) % years
def naturaldelta ( value , months = True ) : now = _now ( ) date , delta = date_and_delta ( value ) if date is None : return value use_months = months seconds = abs ( delta . seconds ) days = abs ( delta . days ) years = days // 365 days = days % 365 months = int ( days // 30.5 ) if not years and days < 1 : if seconds == 0 : return _ ( "a moment" ) elif seconds == 1 : return _ ( "a second" ) elif seconds < 60 : return ngettext ( "%d second" , "%d seconds" , seconds ) % seconds elif 60 <= seconds < 120 : return _ ( "a minute" ) elif 120 <= seconds < 3600 : minutes = seconds // 60 return ngettext ( "%d minute" , "%d minutes" , minutes ) % minutes elif 3600 <= seconds < 3600 * 2 : return _ ( "an hour" ) elif 3600 < seconds : hours = seconds // 3600 return ngettext ( "%d hour" , "%d hours" , hours ) % hours elif years == 0 : if days == 1 : return _ ( "a day" ) if not use_months : return ngettext ( "%d day" , "%d days" , days ) % days else : if not months : return ngettext ( "%d day" , "%d days" , days ) % days elif months == 1 : return _ ( "a month" ) else : return ngettext ( "%d month" , "%d months" , months ) % months elif years == 1 : if not months and not days : return _ ( "a year" ) elif not months : return ngettext ( "1 year, %d day" , "1 year, %d days" , days ) % days elif use_months : if months == 1 : return _ ( "1 year, 1 month" ) else : return ngettext ( "1 year, %d month" , "1 year, %d months" , months ) % months else : return ngettext ( "1 year, %d day" , "1 year, %d days" , days ) % days else : return ngettext ( "%d year" , "%d years" , years ) % years
Given a timedelta or a number of seconds, return a natural
    representation of the amount of time elapsed.  This is similar to
    ``naturaltime``, but does not add tense to the result.  If ``months``
    is True, then a number of months (based on 30.5 days) will be used
    for fuzziness between years.