def parse_duration(duration):
    """
    Convert to duration used by lib.date.  Supports d, w, m, y
    """
    try:
        return int(duration), 'd'
    except:
        units, duration = duration[-1].lower(), duration[:-1]
        if units in 'dwmy':
            return int(duration), units
        else:
            raise
