Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): lazily import dateparser #12655

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion weblate/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from operator import and_, or_
from typing import Any, cast, overload

from dateparser import parse as dateparser_parse
from dateutil.parser import ParserError
from dateutil.parser import parse as dateutil_parse
from django.db import transaction
Expand Down Expand Up @@ -240,6 +239,21 @@ def convert_datetime(self, text, hour=5, minute=55, second=55, microsecond=0):
),
)

return self.human_date_parse(text, hour, minute, second, microsecond)

def human_date_parse(
self,
text: str,
hour: int = 5,
minute: int = 55,
second: int = 55,
microsecond: int = 0,
) -> datetime | tuple[datetime, datetime]:
# Lazily import as this can be expensive
from dateparser import parse as dateparser_parse

tzinfo = timezone.get_current_timezone()

# Attempts to parse the text using dateparser
# If the text is unparsable it will return None
result = dateparser_parse(text)
Expand Down
Loading