def format_time(t, format_spec='dhms'):
	"""
	Return a formatted time string describing the duration of 
	the input in seconds in terms of days,hours,minutes and seconds.
	"""
	if format_spec == '':
		sb, mb, hb, db = True, True, True, True
	else:
		sb = 's' in format_spec
		mb = 'm' in format_spec
		hb = 'h' in format_spec
		db = 'd' in format_spec
	
	t = round(t, 2)
	if t >= 60 and (mb or hb or db):
		m = t // 60
		s = t - m*60
		if m >= 60 and (hb or db):
			h = m // 60
			m = m - h*60
			if h >= 24 and db:
				d = h // 24
				h = h - d*24
			else:
				d = 0
		else:
			h,d = 0,0
	else:
		s = t
		m,h,d = 0,0,0
	
	time_str = ""
	#if format_spec == 's':
	#	time_str += "{}s".format(t)
	if format_spec == '':
		db = not d == 0
		hb = not h == 0
		mb = not m == 0
		sb = not s == 0
	if not (db or hb or mb or sb):
		sb = True
		
	if db:
		time_str += "{:.0f}d ".format(d)
	if hb:
		time_str += "{:.0f}h ".format(h)
	if mb:
		time_str += "{:.0f}m ".format(m)
	if sb:
		time_str += "{:0=4.1f}s".format(s)
	#return "{}d {}h {}m {}s".format(d,h,m,s)
	return time_str