phase-4: preventive maintenance and calibration modules
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user