Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use configured server time when calling RepositoryMeals.get_today() method #4734

Conversation

michaelclark2
Copy link
Contributor

@michaelclark2 michaelclark2 commented Dec 16, 2024

What type of PR is this?

(REQUIRED)

  • bug

What this PR does / why we need it:

(REQUIRED)

When a user calls the endpoint /api/households/mealplans/today , the api uses a hardcoded timezone of UTC to find todays date. This can lead to unexpected results when the user expects the configured timezone to be respected, as it is for the DAILY_SCHEDULE_TIME. To remedy this, I added a timezone argument to the get_today() method of the RepositoryMeals so that when we specifically want to use the configured server time we can, while omitting the flag to respect the UTC timestamps used in the database.

  • added tz argument to get_today method signature with a default of UTC
  • set tz to local tz when calling get_today method in the GroupMealplanController
  • set tz to local tz when calling get_today method in create_timeline_events

Which issue(s) this PR fixes:

(REQUIRED)

Fixes: #4263

Testing

I manually tested this after I setup Mealie and created a mealplan with two entries, one dinner in todays date and then another dinner one day ahead.
I then navigated to the swagger docs page and tested the /api/households/mealplans/today endpoint
I set the TZ environment variables in the docker-compose.yml file to a timezone in the future(i.e. Australia/Sydney) and compared the result to the production build

@michaelclark2 michaelclark2 changed the title fix: Use configured server time when calling /api/households/mealplan/today endpoint fix: Use configured server time when calling /api/households/mealplans/today endpoint Dec 16, 2024
@michaelclark2 michaelclark2 marked this pull request as ready for review December 16, 2024 21:32
@boc-the-git
Copy link
Collaborator

This looks fine to me, thanks @michaelclark2 !

@michael-genson what are your thoughts?
In particular I'm wondering if the following (the only other place to call get_today) should also be updated 🤔

mealplans = repos.meals.get_today()

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boc-the-git yeah we probably want to do this since DAILY_SCHEDULE_TIME uses local time as well

@michaelclark2 would you be able to update it here as well?

@michaelclark2 michaelclark2 changed the title fix: Use configured server time when calling /api/households/mealplans/today endpoint fix: Use configured server time when calling RepositoryMeals.get_today() method Dec 17, 2024
@michael-genson michael-genson enabled auto-merge (squash) December 17, 2024 20:22
@michael-genson michael-genson merged commit 8d32519 into mealie-recipes:mealie-next Dec 17, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Time Zone is different to Mealie Time Zone set in ENV, posting wrong meal of the day on API request.
3 participants