better time usings

This commit is contained in:
2025-10-22 08:14:42 +02:00
parent 04b516a52d
commit 4eede0c8c0
11 changed files with 62 additions and 163 deletions

View File

@@ -14,7 +14,7 @@ All services support both async and sync operations for flexibility.
from __future__ import annotations
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Dict, List, Optional
from sqlalchemy import delete, select, update
@@ -276,7 +276,7 @@ class EpisodeService:
file_path=file_path,
file_size=file_size,
is_downloaded=is_downloaded,
download_date=datetime.utcnow() if is_downloaded else None,
download_date=datetime.now(timezone.utc) if is_downloaded else None,
)
db.add(episode)
await db.flush()
@@ -380,7 +380,7 @@ class EpisodeService:
episode.is_downloaded = True
episode.file_path = file_path
episode.file_size = file_size
episode.download_date = datetime.utcnow()
episode.download_date = datetime.now(timezone.utc)
await db.flush()
await db.refresh(episode)
@@ -597,9 +597,9 @@ class DownloadQueueService:
# Update timestamps based on status
if status == DownloadStatus.DOWNLOADING and not item.started_at:
item.started_at = datetime.utcnow()
item.started_at = datetime.now(timezone.utc)
elif status in (DownloadStatus.COMPLETED, DownloadStatus.FAILED):
item.completed_at = datetime.utcnow()
item.completed_at = datetime.now(timezone.utc)
# Set error message for failed downloads
if status == DownloadStatus.FAILED and error_message:
@@ -807,7 +807,7 @@ class UserSessionService:
"""
query = select(UserSession).where(
UserSession.is_active == True,
UserSession.expires_at > datetime.utcnow(),
UserSession.expires_at > datetime.now(timezone.utc),
)
if user_id:
@@ -833,8 +833,8 @@ class UserSessionService:
session = await UserSessionService.get_by_session_id(db, session_id)
if not session:
return None
session.last_activity = datetime.utcnow()
session.last_activity = datetime.now(timezone.utc)
await db.flush()
await db.refresh(session)
return session
@@ -871,7 +871,7 @@ class UserSessionService:
"""
result = await db.execute(
delete(UserSession).where(
UserSession.expires_at < datetime.utcnow()
UserSession.expires_at < datetime.now(timezone.utc)
)
)
count = result.rowcount