Skip to content

Commit 404a3c1

Browse files
committed
feat(search): lazily import dateparser
It can be expensive to import due to building thousands of regexps at import time (see scrapinghub/dateparser#1181).
1 parent e23f390 commit 404a3c1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

weblate/utils/search.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from operator import and_, or_
1313
from typing import Any, cast, overload
1414

15-
from dateparser import parse as dateparser_parse
1615
from dateutil.parser import ParserError
1716
from dateutil.parser import parse as dateutil_parse
1817
from django.db import transaction
@@ -240,6 +239,21 @@ def convert_datetime(self, text, hour=5, minute=55, second=55, microsecond=0):
240239
),
241240
)
242241

242+
return self.human_date_parse(text, hour, minute, second, microsecond)
243+
244+
def human_date_parse(
245+
self,
246+
text: str,
247+
hour: int = 5,
248+
minute: int = 55,
249+
second: int = 55,
250+
microsecond: int = 0,
251+
) -> datetime | tuple[datetime, datetime]:
252+
# Lazily import as this can be expensive
253+
from dateparser import parse as dateparser_parse
254+
255+
tzinfo = timezone.get_current_timezone()
256+
243257
# Attempts to parse the text using dateparser
244258
# If the text is unparsable it will return None
245259
result = dateparser_parse(text)

0 commit comments

Comments
 (0)