feat: switch all timezone naive datetimes to timezone aware

This commit is contained in:
Iain Learmonth 2024-12-06 16:08:48 +00:00
parent 41fc0a73a5
commit e22abb383c
30 changed files with 322 additions and 226 deletions

View file

@ -3,28 +3,28 @@ import logging
from datetime import datetime, timedelta, timezone
from typing import Optional
from flask import Blueprint, render_template, request, url_for, redirect
from flask import Blueprint, redirect, render_template, request, url_for
from flask.typing import ResponseReturnValue
from markupsafe import Markup
from sqlalchemy import desc, or_, func
from sqlalchemy import desc, func, or_
from app.alarms import alarms_for
from app.models.activity import Activity
from app.models.alarms import Alarm, AlarmState
from app.models.base import Group
from app.models.bridges import Bridge
from app.models.mirrors import Origin, Proxy
from app.models.base import Group
from app.models.onions import Eotk
from app.portal.country import bp as country
from app.portal.cloud import bp as cloud
from app.portal.automation import bp as automation
from app.portal.bridgeconf import bp as bridgeconf
from app.portal.bridge import bp as bridge
from app.portal.bridgeconf import bp as bridgeconf
from app.portal.cloud import bp as cloud
from app.portal.country import bp as country
from app.portal.eotk import bp as eotk
from app.portal.group import bp as group
from app.portal.list import bp as list_
from app.portal.origin import bp as origin
from app.portal.onion import bp as onion
from app.portal.origin import bp as origin
from app.portal.pool import bp as pool
from app.portal.proxy import bp as proxy
from app.portal.smart_proxy import bp as smart_proxy
@ -57,7 +57,7 @@ def calculate_bridge_expiry(b: Bridge) -> str:
logging.warning("Bridge expiry requested by template for a bridge %s that was not expiring.", b.id)
return "Not expiring"
expiry = b.deprecated + timedelta(hours=b.conf.expiry_hours)
countdown = expiry - datetime.utcnow()
countdown = expiry - datetime.now(tz=timezone.utc)
if countdown.days == 0:
return f"{countdown.seconds // 3600} hours"
return f"{countdown.days} days"
@ -66,7 +66,7 @@ def calculate_bridge_expiry(b: Bridge) -> str:
@portal.app_template_filter("mirror_expiry")
def calculate_mirror_expiry(s: datetime) -> str:
expiry = s + timedelta(days=3)
countdown = expiry - datetime.utcnow()
countdown = expiry - datetime.now(tz=timezone.utc)
if countdown.days == 0:
return f"{countdown.seconds // 3600} hours"
return f"{countdown.days} days"