| 1 | from isoduration.parser.exceptions import InvalidFractional |
| 2 | from isoduration.parser.util import is_integer |
| 3 | from isoduration.types import Duration |
| 4 | |
| 5 | |
| 6 | def validate_fractional(duration: Duration) -> None: |
| 7 | fractional_allowed = True |
| 8 | |
| 9 | for _, value in reversed(duration): |
| 10 | if fractional_allowed: |
| 11 | if not value.is_zero(): |
| 12 | # Fractional values are only allowed in the lowest order |
| 13 | # non-zero component. |
| 14 | fractional_allowed = False |
| 15 | elif not is_integer(value): |
| 16 | raise InvalidFractional("Only the lowest order component can be fractional") |