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: Strip Timezone from Timestamps in DB #4310

Conversation

michael-genson
Copy link
Collaborator

@michael-genson michael-genson commented Oct 3, 2024

What type of PR is this?

(REQUIRED)

  • bug

What this PR does / why we need it:

(REQUIRED)

This PR explicitly removes time zones from datetime objects before storing them in the database, then re-adds the UTC timezone when retrieving them.

We do this because when using naive datetimes with postgres (which is what Mealie uses), postgres will convert datetimes to local time when storing. So, for instance, if we send this dt to postgres:

2024-10-03T14:34:32Z

And the postgres db timezone is in America/Chicago, it will store the dt as:

2024-10-03T08:34:32

Note that the time is not UTC, and the timezone info is now removed. So, once we retrieve it, we assume 2024-10-03T08:34:32 is UTC, and our timestamps are off.

Which issue(s) this PR fixes:

(REQUIRED)

Fixes #4288

Special notes for your reviewer:

Pretty simple fix, super annoying to debug.

Testing

(fill-in or delete this section)

I set my dev postgres db to Europe/Bratislava and Mealie as UTC and observed the issue in #4288. After this fix I no longer had any issues, and I manually verified the timestamps were correct (I also checked on SQLite just to make sure).

@Kuchenpirat Kuchenpirat enabled auto-merge (squash) October 6, 2024 06:22
@Kuchenpirat Kuchenpirat merged commit b0ed242 into mealie-recipes:mealie-next Oct 6, 2024
13 checks passed
@michael-genson michael-genson deleted the fix/handle-utc-in-postgres-with-timezone branch October 15, 2024 14:15
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.

[BUG] - Items in shopping list not showing when added
2 participants