refactor: update timestamp handling to use timezone-aware datetime
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from app.database import db
|
||||
from sqlalchemy import Boolean, DateTime, Integer, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import db
|
||||
|
||||
|
||||
class SoundType(Enum):
|
||||
"""Sound type enumeration."""
|
||||
@@ -75,13 +77,13 @@ class Sound(db.Model):
|
||||
# Timestamps
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
default=datetime.utcnow,
|
||||
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
|
||||
nullable=False,
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow,
|
||||
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
|
||||
onupdate=lambda: datetime.now(tz=ZoneInfo("UTC")),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
@@ -114,7 +116,7 @@ class Sound(db.Model):
|
||||
def increment_play_count(self) -> None:
|
||||
"""Increment the play count for this sound."""
|
||||
self.play_count += 1
|
||||
self.updated_at = datetime.utcnow()
|
||||
self.updated_at = datetime.now(tz=ZoneInfo("UTC"))
|
||||
db.session.commit()
|
||||
|
||||
def set_normalized_info(
|
||||
@@ -130,7 +132,7 @@ class Sound(db.Model):
|
||||
self.normalized_size = normalized_size
|
||||
self.normalized_hash = normalized_hash
|
||||
self.is_normalized = True
|
||||
self.updated_at = datetime.utcnow()
|
||||
self.updated_at = datetime.now(tz=ZoneInfo("UTC"))
|
||||
|
||||
def clear_normalized_info(self) -> None:
|
||||
"""Clear normalized sound information."""
|
||||
@@ -139,7 +141,7 @@ class Sound(db.Model):
|
||||
self.normalized_hash = None
|
||||
self.normalized_size = None
|
||||
self.is_normalized = False
|
||||
self.updated_at = datetime.utcnow()
|
||||
self.updated_at = datetime.now(tz=ZoneInfo("UTC"))
|
||||
|
||||
def update_file_info(
|
||||
self,
|
||||
@@ -153,7 +155,7 @@ class Sound(db.Model):
|
||||
self.duration = duration
|
||||
self.size = size
|
||||
self.hash = hash_value
|
||||
self.updated_at = datetime.utcnow()
|
||||
self.updated_at = datetime.now(tz=ZoneInfo("UTC"))
|
||||
|
||||
@classmethod
|
||||
def find_by_hash(cls, hash_value: str) -> Optional["Sound"]:
|
||||
|
||||
Reference in New Issue
Block a user