Skip to content

Commit

Permalink
pass local timezone to get_today from endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelclark2 committed Dec 16, 2024
1 parent e863914 commit 6980b0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions mealie/repos/repository_meals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@


class RepositoryMeals(HouseholdRepositoryGeneric[ReadPlanEntry, GroupMealPlan]):
def get_today(self, use_server_time = False) -> list[ReadPlanEntry]:
def get_today(self, tz=UTC) -> list[ReadPlanEntry]:
if not self.household_id:
raise Exception("household_id not set")

today = datetime.now().date() if use_server_time else datetime.now(tz=UTC).date()
today = datetime.now(tz=tz).date()
stmt = select(GroupMealPlan).filter(
GroupMealPlan.date == today, GroupMealPlan.household_id == self.household_id
)
Expand Down
4 changes: 3 additions & 1 deletion mealie/routes/households/controller_mealplan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date
from functools import cached_property

from dateutil.tz import tzlocal
from fastapi import APIRouter, Depends, HTTPException

from mealie.core.exceptions import mealie_registered_exceptions
Expand Down Expand Up @@ -115,7 +116,8 @@ def create_one(self, data: CreatePlanEntry):

@router.get("/today")
def get_todays_meals(self):
return self.repo.get_today(use_server_time=True)
local_tz = tzlocal()
return self.repo.get_today(tz=local_tz)

@router.post("/random", response_model=ReadPlanEntry)
def create_random_meal(self, data: CreateRandomEntry):
Expand Down

0 comments on commit 6980b0a

Please sign in to comment.