phase-4: preventive maintenance and calibration modules

This commit is contained in:
Atharv1705
2026-11-12 14:16:38 +05:30
parent 905f6735a7
commit d3f22ba444
26 changed files with 5066 additions and 27 deletions
+10
View File
@@ -1,3 +1,4 @@
import calendar
from datetime import date, datetime, timezone
import json
import pytz
@@ -56,6 +57,15 @@ def format_date(d: date | None) -> str | None:
return d.strftime("%d-%b-%Y")
def add_months(d: date, months: int) -> date:
"""Add calendar months to a date, clamping day-of-month to the target month's length."""
total_months = (d.year * 12 + (d.month - 1)) + months
year, zero_month = divmod(total_months, 12)
month = zero_month + 1
max_day = calendar.monthrange(year, month)[1]
return date(year, month, min(d.day, max_day))
def format_duration(minutes: int | None) -> str:
if minutes is None:
return "\u2014"