File size: 1,511 Bytes
d1ceb73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from __future__ import annotations
from typing import TYPE_CHECKING
from isoduration.formatter.exceptions import DurationFormattingException
if TYPE_CHECKING: # pragma: no cover
from isoduration.types import DateDuration, Duration
def check_global_sign(duration: Duration) -> int:
is_date_zero = (
duration.date.years == 0
and duration.date.months == 0
and duration.date.days == 0
and duration.date.weeks == 0
)
is_time_zero = (
duration.time.hours == 0
and duration.time.minutes == 0
and duration.time.seconds == 0
)
is_date_negative = (
duration.date.years <= 0
and duration.date.months <= 0
and duration.date.days <= 0
and duration.date.weeks <= 0
)
is_time_negative = (
duration.time.hours <= 0
and duration.time.minutes <= 0
and duration.time.seconds <= 0
)
if not is_date_zero and not is_time_zero:
if is_date_negative and is_time_negative:
return -1
elif not is_date_zero:
if is_date_negative:
return -1
elif not is_time_zero:
if is_time_negative:
return -1
return +1
def validate_date_duration(date_duration: DateDuration) -> None:
if date_duration.weeks:
if date_duration.years or date_duration.months or date_duration.days:
raise DurationFormattingException(
"Weeks are incompatible with other date designators"
)
|