amonone/web/template.py
def age(from_date, since_date = None, target_tz=None, include_seconds=False):
	'''
	Returns the age as a string
	'''
	if since_date is None:
		since_date = datetime.now(target_tz)

	distance_in_time = since_date - from_date
	distance_in_seconds = int(round(abs(distance_in_time.days * 86400 + distance_in_time.seconds)))
	distance_in_minutes = int(round(distance_in_seconds/60))

	if distance_in_minutes <= 1:
		if include_seconds:
			for remainder in [5, 10, 20]:
				if distance_in_seconds < remainder:
					return "less than %s seconds" % remainder
			if distance_in_seconds < 40:
				return "half a minute"
			elif distance_in_seconds < 60:
				return "less than a minute"
			else:
				return "1 minute"
		else:
			if distance_in_minutes == 0:
				return "less than a minute"
			else:
				return "1 minute"
	elif distance_in_minutes < 45:
		return "%s minutes" % distance_in_minutes
	elif distance_in_minutes < 90:
		return "about 1 hour"
	elif distance_in_minutes < 1440:
		return "about %d hours" % (round(distance_in_minutes / 60.0))
	elif distance_in_minutes < 2880:
		return "1 day"
	elif distance_in_minutes < 43220:
		return "%d days" % (round(distance_in_minutes / 1440))
	elif distance_in_minutes < 86400:
		return "about 1 month"
	elif distance_in_minutes < 525600:
		return "%d months" % (round(distance_in_minutes / 43200))
	elif distance_in_minutes < 1051200:
		return "about 1 year"
	else:
		return "over %d years" % (round(distance_in_minutes / 525600))

	Returns the age as a string
	
Returns the age as a string
Returns the age as a string
def age(from_date, since_date = None, target_tz=None, include_seconds=False):
	if since_date is None:
		since_date = datetime.now(target_tz)
	distance_in_time = since_date - from_date
	distance_in_seconds = int(round(abs(distance_in_time.days * 86400 + distance_in_time.seconds)))
	distance_in_minutes = int(round(distance_in_seconds/60))
	if distance_in_minutes <= 1:
		if include_seconds:
			for remainder in [5, 10, 20]:
				if distance_in_seconds < remainder:
					return "less than %s seconds" % remainder
			if distance_in_seconds < 40:
				return "half a minute"
			elif distance_in_seconds < 60:
				return "less than a minute"
			else:
				return "1 minute"
		else:
			if distance_in_minutes == 0:
				return "less than a minute"
			else:
				return "1 minute"
	elif distance_in_minutes < 45:
		return "%s minutes" % distance_in_minutes
	elif distance_in_minutes < 90:
		return "about 1 hour"
	elif distance_in_minutes < 1440:
		return "about %d hours" % (round(distance_in_minutes / 60.0))
	elif distance_in_minutes < 2880:
		return "1 day"
	elif distance_in_minutes < 43220:
		return "%d days" % (round(distance_in_minutes / 1440))
	elif distance_in_minutes < 86400:
		return "about 1 month"
	elif distance_in_minutes < 525600:
		return "%d months" % (round(distance_in_minutes / 43200))
	elif distance_in_minutes < 1051200:
		return "about 1 year"
	else:
		return "over %d years" % (round(distance_in_minutes / 525600))
def age ( from_date , since_date = None , target_tz = None , include_seconds = False ) : if since_date is None : since_date = datetime . now ( target_tz ) distance_in_time = since_date - from_date distance_in_seconds = int ( round ( abs ( distance_in_time . days * 86400 + distance_in_time . seconds ) ) ) distance_in_minutes = int ( round ( distance_in_seconds / 60 ) ) if distance_in_minutes <= 1 : if include_seconds : for remainder in [ 5 , 10 , 20 ] : if distance_in_seconds < remainder : return "less than %s seconds" % remainder if distance_in_seconds < 40 : return "half a minute" elif distance_in_seconds < 60 : return "less than a minute" else : return "1 minute" else : if distance_in_minutes == 0 : return "less than a minute" else : return "1 minute" elif distance_in_minutes < 45 : return "%s minutes" % distance_in_minutes elif distance_in_minutes < 90 : return "about 1 hour" elif distance_in_minutes < 1440 : return "about %d hours" % ( round ( distance_in_minutes / 60.0 ) ) elif distance_in_minutes < 2880 : return "1 day" elif distance_in_minutes < 43220 : return "%d days" % ( round ( distance_in_minutes / 1440 ) ) elif distance_in_minutes < 86400 : return "about 1 month" elif distance_in_minutes < 525600 : return "%d months" % ( round ( distance_in_minutes / 43200 ) ) elif distance_in_minutes < 1051200 : return "about 1 year" else : return "over %d years" % ( round ( distance_in_minutes / 525600 ) )
Returns the age as a string
Returns the age as a string
'''
	Returns the age as a string
	'''
from_date
since_date
target_tz
include_seconds