Skip to content

Commit

Permalink
Modify to accept regular expression for separator argument of from_ra…
Browse files Browse the repository at this point in the history
…nge_text method: #41

Co-authored-by: Felix Delattre <felix.delattre@up42.com>
  • Loading branch information
thombashi and pantierra committed Feb 11, 2023
1 parent 0ce0c2d commit 6976a8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions datetimerange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def __normalize_datetime_value(self, value, timezone):
def from_range_text(
cls,
range_text: str,
separator: str = "-",
separator: str = r"\s+\-\s+",
start_time_format: Optional[str] = None,
end_time_format: Optional[str] = None,
) -> "DateTimeRange":
Expand All @@ -864,13 +864,13 @@ def from_range_text(
e.g. ``2021-01-23T10:00:00+0400 - 2021-01-232T10:10:00+0400``
:param str separator:
Text that separating the ``range_text``.
Regular expression that separating the ``range_text`` to start and end time.
:return: DateTimeRange
Created instance.
"""

dattime_ranges = re.split(rf"\s+{re.escape(separator)}\s+", range_text.strip())
dattime_ranges = re.split(separator, range_text.strip())
if len(dattime_ranges) != 2:
raise ValueError("range_text should include two datetime that separated by hyphen")

Expand Down
4 changes: 2 additions & 2 deletions test/test_dtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ class TestDateTimeRange_from_range_text:
[
[
f"{START_DATETIME_TEXT} - {END_DATETIME_TEXT}",
"-",
r"\s+\-\s+",
DateTimeRange(START_DATETIME_TEXT, END_DATETIME_TEXT),
],
[
Expand All @@ -1252,7 +1252,7 @@ class TestDateTimeRange_from_range_text:
],
[
f"{START_DATETIME_TEXT} - {END_DATETIME_TEXT}",
"-",
r"\s+\-\s+",
DateTimeRange(START_DATETIME_TEXT, END_DATETIME_TEXT),
],
],
Expand Down

0 comments on commit 6976a8c

Please sign in to comment.