fix age to start at 0 on start date of cycle instead of 1

This commit is contained in:
Alberto-Audrix committed 2026-09-02 09:58:59 +07:00
1 parent 3411ed4391
commit 54eb277c16
7 files changed
+33 -10

No files matched your search

+4 -2
View File
@@ -116,13 +116,15 @@ class Cycle(models.Model):
@property
def current_day(self) -> int:
"""0-based cycle age: start_date is day 0."""
from apps.operations.services.visibility import visible_through_date
effective = visible_through_date()
if effective < self.start_date:
return 0
elapsed = (effective - self.start_date).days + 1
return min(max(elapsed, 1), self.total_days)
elapsed = (effective - self.start_date).days
max_day = max(self.total_days - 1, 0)
return min(max(elapsed, 0), max_day)
@property
def visible_through_date(self) -> date: