def strtime(time):
    """Takes a number of seconds; returns a formatted duration string"""
    years, days, hours, mins = 0, 0, 0, 0
    timestr = ""
    if time > 31536000:
        years = int(time / 31536000)
        time = time - (31536000 * years)
    if time > 86400:
        days = int(time / 86400)
        time = time - (86400 * days)
    if time > 3600:
        hours = int(time / 3600)
        time = time - (3600 * hours)
    if time > 60:
        mins = int(time / 60)
        time = time - (60 * mins)
    if years > 0:
        return "{}y {}d {:02d}h {:02d}min {:02d}s".format(years, days, hours, mins, int(time))
    if days > 0:
        return "{}d {:02d}h {:02d}min {:02d}s".format(days, hours, mins, int(time))
    return "{:02d}h {:02d}min {:02d}s".format(hours, mins, int(time))