a unit of time is any particular time interval used as a standard way of measuring or expressing duration the base unit of time in the international system of units si and by extension most of the western world is the second defined as about 9 billion oscillations of the caesium atom https en wikipedia orgwikiunitoftime convert time from one unit to another using the timechart above converttime3600 seconds hours 1 0 converttime3500 seconds hours 0 972 converttime1 days hours 24 0 converttime120 minutes seconds 7200 0 converttime2 weeks days 14 0 converttime0 5 hours minutes 30 0 converttime3600 seconds hours traceback most recent call last valueerror timevalue must be a nonnegative number converttimehello hours minutes traceback most recent call last valueerror timevalue must be a nonnegative number converttime0 1 2 weeks days traceback most recent call last valueerror timevalue must be a nonnegative number converttime1 cool century doctest ellipsis traceback most recent call last valueerror invalid unit cool is not in seconds minutes hours days weeks converttime1 seconds hot doctest ellipsis traceback most recent call last valueerror invalid unit hot is not in seconds minutes hours days weeks 1 minute 60 sec 1 hour 60 minutes 3600 seconds 1 day 24 hours 1440 min 86400 sec 1 week 7d 168hr 10080min 604800 sec approximate value for a month in seconds approximate value for a year in seconds convert time from one unit to another using the time_chart above convert_time 3600 seconds hours 1 0 convert_time 3500 seconds hours 0 972 convert_time 1 days hours 24 0 convert_time 120 minutes seconds 7200 0 convert_time 2 weeks days 14 0 convert_time 0 5 hours minutes 30 0 convert_time 3600 seconds hours traceback most recent call last valueerror time_value must be a non negative number convert_time hello hours minutes traceback most recent call last valueerror time_value must be a non negative number convert_time 0 1 2 weeks days traceback most recent call last valueerror time_value must be a non negative number convert_time 1 cool century doctest ellipsis traceback most recent call last valueerror invalid unit cool is not in seconds minutes hours days weeks convert_time 1 seconds hot doctest ellipsis traceback most recent call last valueerror invalid unit hot is not in seconds minutes hours days weeks
time_chart: dict[str, float] = {
    "seconds": 1.0,
    "minutes": 60.0,  
    "hours": 3600.0,  
    "days": 86400.0,  
    "weeks": 604800.0,  
    "months": 2629800.0,  
    "years": 31557600.0,  
}

time_chart_inverse: dict[str, float] = {
    key: 1 / value for key, value in time_chart.items()
}


def convert_time(time_value: float, unit_from: str, unit_to: str) -> float:
    
    if not isinstance(time_value, (int, float)) or time_value < 0:
        msg = "'time_value' must be a non-negative number."
        raise ValueError(msg)

    unit_from = unit_from.lower()
    unit_to = unit_to.lower()
    if unit_from not in time_chart or unit_to not in time_chart:
        invalid_unit = unit_from if unit_from not in time_chart else unit_to
        msg = f"Invalid unit {invalid_unit} is not in {', '.join(time_chart)}."
        raise ValueError(msg)

    return round(
        time_value * time_chart[unit_from] * time_chart_inverse[unit_to],
        3,
    )


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    print(f"{convert_time(3600,'seconds', 'hours') = :,}")
    print(f"{convert_time(360, 'days', 'months') = :,}")
    print(f"{convert_time(360, 'months', 'years') = :,}")
    print(f"{convert_time(1, 'years', 'seconds') = :,}")