import logging


def convert_time (timeX):
    """ Given time value term such as 90s, 15m, 20h, 3d, 2w return int seconds and units.
        <1h> returns (3600, "hours")
    If no units suffix, the value is interpreted as secs.
        <90> returns (90, "secs ")
    """
    if type(timeX) is int:
        return timeX, "secs "           # Case Int
    try:
        return int(timeX), "secs "      # Case Str without units
    except:
        pass
    try:                                # Case Str with units
        time_value = int(timeX[:-1])
        time_unit =  timeX[-1:].lower()
        if time_unit == "s":
            return time_value, "secs "
        if time_unit == "m":
            return time_value * 60, "mins "
        if time_unit == "h":
            return time_value * 60*60, "hours"
        if time_unit == "d":
            return time_value * 60*60*24, "days "
        if time_unit == "w":
            return time_value * 60*60*24*7, "weeks"
        raise ValueError(f"Illegal time units <{time_unit}>")
    except Exception as e:
        logging.error (f"ERROR:  Could not convert time value <{timeX}>\n  {e}")
        raise