Skip to content

Commit

Permalink
Fully ensure date_added is in UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
le717 committed Jun 8, 2024
1 parent c02872c commit 304091a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/core/database/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import UTC, datetime
from typing import Any

from flask_sqlalchemy import SQLAlchemy
Expand All @@ -16,6 +16,11 @@ class Base(DeclarativeBase): ...
db = SQLAlchemy(model_class=Base)


def now_in_utc() -> datetime:
"""Get the current datetime, expressed in UTC."""
return datetime.now(tz=UTC)


class HelperMethods:
def as_dict(self) -> dict[str, Any]:
"""Return a model as a dictionary."""
Expand All @@ -40,8 +45,8 @@ class WebLink(HelperMethods, Base):
)
date_added: Mapped[datetime] = mapped_column(
nullable=False,
default=datetime.now,
onupdate=datetime.now,
default=now_in_utc,
onupdate=now_in_utc,
)
is_dead: Mapped[bool] = mapped_column(default=False)
is_web_archive: Mapped[bool] = mapped_column(default=False)
Expand Down

0 comments on commit 304091a

Please sign in to comment.