fix: accept datetime ranges in parse_date_range

With period.dynamic: true and period.precision: datetime, running
without --date crashed: compute_next_period() returns a datetime range
(YYYY-MM-DDTHH:MM:SS), which parse_date_range() rejected with a
fullmatch against YYYY-MM-DD only.

parse_date_range now accepts YYYY-MM-DDTHH:MM:SS--YYYY-MM-DDTHH:MM:SS
in addition to plain date ranges, returning datetime strings unchanged
(pass-through, matching compute_next_period output). Mixed-precision
ranges, invalid times and reversed ranges are still rejected with the
existing error messages; date-range behavior is unchanged.

Closes #59
This commit is contained in:
Кокос Артем Николаевич
2026-07-17 11:44:13 +07:00
parent d135408f5e
commit c4ec23048a
2 changed files with 18 additions and 9 deletions

View File

@@ -30,6 +30,10 @@ def _reset_config_overrides():
[
("2026-01-01--2026-01-31", ("2026-01-01", "2026-01-31")),
(" 2026-01-01 -- 2026-01-31 ", ("2026-01-01", "2026-01-31")),
(
"2026-06-01T00:00:00--2026-06-30T23:59:59",
("2026-06-01T00:00:00", "2026-06-30T23:59:59"),
),
],
)
def test_parse_date_range_valid(date_arg, expected):
@@ -43,6 +47,9 @@ def test_parse_date_range_valid(date_arg, expected):
"2026-1-01--2026-01-31",
"2026-02-30--2026-03-01",
"2026-02-01--2026-01-31",
"2026-06-01T25:00:00--2026-06-30T23:59:59",
"2026-06-01--2026-06-30T23:59:59",
"2026-06-30T23:59:59--2026-06-01T00:00:00",
],
)
def test_parse_date_range_invalid(date_arg):
@@ -1372,11 +1379,6 @@ class TestReportNoTimeIntegration:
# ---------------------------------------------------------------------------
@pytest.mark.xfail(
strict=True,
reason="bug #59: parse_date_range rejects datetime range produced by "
"dynamic period with precision=datetime when --date is omitted",
)
@mock.patch.dict(os.environ, VALID_ENV, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
def test_cli_dynamic_datetime_period_without_date(mock_fetch, tmp_path):