|
17 | 17 | ElectricalComponentCategory, |
18 | 18 | ) |
19 | 19 | from frequenz.client.dispatch.__main__ import cli |
| 20 | +from frequenz.client.dispatch._cli_types import FuzzyDateTime |
20 | 21 | from frequenz.client.dispatch.recurrence import ( |
21 | 22 | EndCriteria, |
22 | 23 | Frequency, |
@@ -739,3 +740,30 @@ async def test_delete_command( |
739 | 740 | assert expected_output in result.output |
740 | 741 | if dispatches: |
741 | 742 | assert len(fake_client.dispatches(MicrogridId(1))) == 0 |
| 743 | + |
| 744 | + |
| 745 | +def test_fuzzy_datetime_date_only() -> None: |
| 746 | + """Test that date-only inputs are parsed as midnight.""" |
| 747 | + fuzzy_dt = FuzzyDateTime() |
| 748 | + |
| 749 | + # Test date-only input |
| 750 | + result = fuzzy_dt.convert("2025-08-06", None, None) |
| 751 | + assert isinstance(result, datetime) |
| 752 | + # Check that time is set to midnight in UTC (accounting for timezone conversion) |
| 753 | + # For Europe/Berlin (UTC+2), midnight local time becomes 22:00 UTC previous day |
| 754 | + assert result.hour in [ |
| 755 | + 0, |
| 756 | + 22, |
| 757 | + ] # Could be 0 (UTC) or 22 (UTC for Europe/Berlin midnight) |
| 758 | + assert result.minute == 0 |
| 759 | + assert result.second == 0 |
| 760 | + assert result.microsecond == 0 |
| 761 | + |
| 762 | + # Test date-time input (should preserve time) |
| 763 | + result_with_time = fuzzy_dt.convert("2025-08-06 14:30:15", None, None) |
| 764 | + assert isinstance(result_with_time, datetime) |
| 765 | + # Time should be preserved (accounting for timezone conversion) |
| 766 | + # For Europe/Berlin (UTC+2), 14:30 local becomes 12:30 UTC |
| 767 | + assert result_with_time.hour in [12, 14] # Could be 12 (UTC) or 14 (local) |
| 768 | + assert result_with_time.minute == 30 |
| 769 | + assert result_with_time.second == 15 |
0 commit comments