Parse a time input into a :class:`Time` instance. Args: i (str | int | Time): The time input. default_int_unit (TimeUnit, optional): The default unit to use if ``i`` is an integer >>> Time.from_input("5ep") Time(5, TimeUnit.EPOCH) >>> Time.fr
(
cls,
i: Union[str, int, float, 'Time'],
default_int_unit: Optional[Union[TimeUnit, str]] = None,
)
| 389 | |
| 390 | @classmethod |
| 391 | def from_input( |
| 392 | cls, |
| 393 | i: Union[str, int, float, 'Time'], |
| 394 | default_int_unit: Optional[Union[TimeUnit, str]] = None, |
| 395 | ) -> Time: |
| 396 | """Parse a time input into a :class:`Time` instance. |
| 397 | |
| 398 | Args: |
| 399 | i (str | int | Time): The time input. |
| 400 | default_int_unit (TimeUnit, optional): The default unit to use if ``i`` is an integer |
| 401 | |
| 402 | >>> Time.from_input("5ep") |
| 403 | Time(5, TimeUnit.EPOCH) |
| 404 | >>> Time.from_input(5, TimeUnit.EPOCH) |
| 405 | Time(5, TimeUnit.EPOCH) |
| 406 | |
| 407 | Returns: |
| 408 | Time: An instance of :class:`Time`. |
| 409 | """ |
| 410 | if isinstance(i, Time): |
| 411 | return i |
| 412 | |
| 413 | if isinstance(i, str): |
| 414 | return Time.from_timestring(i) |
| 415 | |
| 416 | if isinstance(i, int) or isinstance(i, float): |
| 417 | if default_int_unit is None: |
| 418 | raise RuntimeError('default_int_unit must be specified when constructing Time from an integer.') |
| 419 | return Time(i, default_int_unit) |
| 420 | |
| 421 | raise RuntimeError(f'Cannot convert type {i} to {cls.__name__}') |
| 422 | |
| 423 | @classmethod |
| 424 | def from_timestring(cls, timestring: str) -> Time: |