Documentation

Identify Function Time Unit

This action identifies and returns a valid time unit from the input provided. The function accepts various time units as input, ordered from largest to smallest, and returns the correctly formatted time unit if it's valid. Type hints have been set to suggest the accepted values in order.

Input: A string representing a time unit (case-insensitive)
Accepted values (in order): Years, Months, Weeks, Days, Hours, Minutes, Seconds

Output:

  • If the input matches one of the accepted time units (regardless of case), the function returns the correctly capitalised time unit.
  • If the input is not a valid time unit, the function returns an error message.

Example:
Input: "weeks" or "WEEKS" or "Weeks"
Output: "Weeks"

Input: "Fortnight"
Output: "Invalid input. Please enter a valid time unit (Years, Months, Weeks, Days, Hours, Minutes, Seconds)."