Skip to content

Commit

Permalink
Event: Replaces db time by sedate
Browse files Browse the repository at this point in the history
TYPE: Feature
LINK: None
  • Loading branch information
Tschuppi81 authored May 16, 2024
1 parent 1ca6821 commit 9b4c4d8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/onegov/event/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from sqlalchemy import Column
from sqlalchemy import desc
from sqlalchemy import Enum
from sqlalchemy import func
from sqlalchemy import Text
from sqlalchemy.orm import object_session
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -233,18 +232,19 @@ def latest_occurrence(self) -> Occurrence | None:
"""

now = utcnow()
base = self.base_query
current = base.filter(and_(
Occurrence.start <= func.now(),
Occurrence.end >= func.now()
Occurrence.start <= now,
Occurrence.end >= now
)).order_by(Occurrence.start).limit(1)

future = base.filter(
Occurrence.start >= func.now()
Occurrence.start >= now
).order_by(Occurrence.start).limit(1)

past = base.filter(
Occurrence.end <= func.now()
Occurrence.end <= now
).order_by(desc(Occurrence.start))

return current.union_all(future, past).first()
Expand Down

0 comments on commit 9b4c4d8

Please sign in to comment.