"""Dashboard publish cutoff — day D data visible from 17:00 WIB on day D.""" from __future__ import annotations from datetime import date, datetime, time, timedelta from django.conf import settings from django.utils import timezone def dashboard_publish_time() -> time: hour = int(getattr(settings, "DASHBOARD_PUBLISH_HOUR", 17)) minute = int(getattr(settings, "DASHBOARD_PUBLISH_MINUTE", 0)) return time(hour, minute) def visible_through_date(now: datetime | None = None) -> date: """Latest calendar date (WIB) allowed on dashboard reads.""" if now is None: now = timezone.localtime() elif timezone.is_naive(now): now = timezone.make_aware(now, timezone.get_current_timezone()) else: now = timezone.localtime(now) today = now.date() if now.time() < dashboard_publish_time(): return today - timedelta(days=1) return today