diff --git a/app/routers/web.py b/app/routers/web.py index c11fd4b..bb5a5fc 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -47,6 +47,14 @@ def _to_local(dt: datetime) -> datetime: return dt.astimezone(_CST) +def _to_utc(dt_str: str) -> datetime: + """Parse local datetime-local string and convert to UTC.""" + dt = datetime.fromisoformat(dt_str) + if dt.tzinfo is None: + dt = dt.replace(tzinfo=_CST) + return dt.astimezone(timezone.utc).replace(tzinfo=None) + + templates.env.filters["to_local"] = _to_local @@ -218,7 +226,7 @@ def admin_add_invite( if limit_type == "uses" and max_uses: m_uses = max_uses elif limit_type == "expires" and expires_at: - exp_at = datetime.fromisoformat(expires_at) + exp_at = _to_utc(expires_at) new_code = InviteCode( code=code, max_uses=m_uses, expires_at=exp_at, use_count=0, created_by=user.id, @@ -251,7 +259,7 @@ def admin_edit_invite( code_obj.max_uses = max_uses code_obj.expires_at = None elif limit_type == "expires" and expires_at: - code_obj.expires_at = datetime.fromisoformat(expires_at) + code_obj.expires_at = _to_utc(expires_at) code_obj.max_uses = None else: code_obj.max_uses = None diff --git a/app/templates/admin_invites.html b/app/templates/admin_invites.html index 68bcc6c..0d6cd55 100644 --- a/app/templates/admin_invites.html +++ b/app/templates/admin_invites.html @@ -28,11 +28,11 @@ -