def time_string(t):
    """Convert time given in seconds in more readable format
    such as ps, ns, ms, s, min, hours and days."""
    if t == "off": return "off"
    try: t = float(t)
    except: return "off"
    if t != t: return "off" # not a number
    if t == 0: return "0"
    if abs(t) < 0.5e-12: return "0"
    if abs(t) < 999e-12: return "%.3gps" % (t*1e12)
    if abs(t) < 999e-9: return "%.3gns" % (t*1e9)
    if abs(t) < 999e-6: return "%.3gus" % (t*1e6)
    if abs(t) < 999e-3: return "%.3gms" % (t*1e3)
    if abs(t) <= 59: return "%.3gs" % t
    if abs(t) <= 3600-1: return "%02d:%02dmin" % (t/60,round(t%60))
    if abs(t) <= 24*3600-1: return "%d:%02dh" % (round(t/3600),round(t%3600/60))
    return str(int(t/(24*3600)))+"d "+str(int(round(t%(24*3600)/3600)))+"h"