Skip to content

Commit

Permalink
fix: make check_date_operators work with dateutil < 2.8.1 (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
snosratiershad authored Sep 18, 2023
1 parent df5e0de commit 7a3b6d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions UnleashClient/constraints/Constraint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=invalid-name, too-few-public-methods, use-a-generator
from datetime import datetime
from enum import Enum
from typing import Optional, Union
from typing import Any, Optional, Union

import semver
from dateutil.parser import ParserError, parse
from dateutil.parser import parse

from UnleashClient.utils import LOGGER, get_identifier

Expand Down Expand Up @@ -123,13 +123,22 @@ def check_date_operators(self, context_value: Union[datetime, str]) -> bool:
return_value = False
parsing_exception = False

DateUtilParserError: Any

try:
from dateutil.parser import ParserError

DateUtilParserError = ParserError
except ImportError:
DateUtilParserError = ValueError

try:
parsed_date = parse(self.value)
if isinstance(context_value, str):
context_date = parse(context_value)
else:
context_date = context_value
except ParserError:
except DateUtilParserError:
LOGGER.error(f"Unable to parse date: {self.value}")
parsing_exception = True

Expand Down

0 comments on commit 7a3b6d3

Please sign in to comment.