phase-0: scaffold backend and frontend shell
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from datetime import date, datetime, timezone
|
||||
import pytz
|
||||
|
||||
KOLKATA = pytz.timezone("Asia/Kolkata")
|
||||
|
||||
|
||||
def utc_now() -> datetime:
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
def effective_today() -> date:
|
||||
"""Returns demo_as_of_date from settings if set, else real today (Asia/Kolkata).
|
||||
Phase 0: always real today. Phase 1 wires in DB settings lookup."""
|
||||
return datetime.now(KOLKATA).date()
|
||||
|
||||
|
||||
def to_kolkata(dt: datetime) -> datetime:
|
||||
return dt.astimezone(KOLKATA)
|
||||
|
||||
|
||||
def format_datetime(dt: datetime | None) -> str | None:
|
||||
if dt is None:
|
||||
return None
|
||||
local = to_kolkata(dt) if dt.tzinfo else KOLKATA.localize(dt)
|
||||
return local.strftime("%d-%b-%Y %H:%M")
|
||||
|
||||
|
||||
def format_date(d: date | None) -> str | None:
|
||||
if d is None:
|
||||
return None
|
||||
return d.strftime("%d-%b-%Y")
|
||||
|
||||
|
||||
def format_duration(minutes: int | None) -> str:
|
||||
if minutes is None:
|
||||
return "\u2014"
|
||||
minutes = int(minutes)
|
||||
d, rem = divmod(minutes, 1440)
|
||||
h, m = divmod(rem, 60)
|
||||
parts = []
|
||||
if d:
|
||||
parts.append(f"{d}d")
|
||||
if h:
|
||||
parts.append(f"{h}h")
|
||||
if m or not parts:
|
||||
parts.append(f"{m}m")
|
||||
return " ".join(parts)
|
||||
Reference in New Issue
Block a user