diff --git a/components/collector/src/collector_utilities/functions.py b/components/collector/src/collector_utilities/functions.py index db7f26daa9..2e184d1350 100644 --- a/components/collector/src/collector_utilities/functions.py +++ b/components/collector/src/collector_utilities/functions.py @@ -82,7 +82,8 @@ def days_ago(date_time: datetime) -> int: def days_to_go(date_time: datetime) -> int: """Return the days remaining until the date/time.""" - return (date_time - datetime.now(tz=date_time.tzinfo)).days + difference = (date_time - datetime.now(tz=date_time.tzinfo)).days + return max(difference, 0) def is_regexp(string: str) -> bool: diff --git a/components/collector/tests/source_collectors/calendar/test_time_remaining.py b/components/collector/tests/source_collectors/calendar/test_time_remaining.py index 83d7fa60df..161a2a3531 100644 --- a/components/collector/tests/source_collectors/calendar/test_time_remaining.py +++ b/components/collector/tests/source_collectors/calendar/test_time_remaining.py @@ -19,4 +19,4 @@ async def test_time_remaining(self): async def test_time_remaining_with_default(self): """Test the number of days without user-specified date.""" response = await self.collect() - self.assert_measurement(response, value=str((datetime(2021, 1, 1) - datetime.now()).days)) + self.assert_measurement(response, value="0") diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 5b10d9225d..aeb66afd8b 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -16,6 +16,7 @@ If your currently installed *Quality-time* version is v4.0.0 or older, please re ### Fixed +- Prevent negative time remaining in the calendar source. Fixes [#5267](https://github.com/ICTU/quality-time/issues/5267). - Tags were not printed correctly in the reference manual. Fixes [#5282](https://github.com/ICTU/quality-time/issues/5282). - Prevent users from entering negative desired response times. Fixes [#5328](https://github.com/ICTU/quality-time/issues/5328).