Skip to content

feat(core): store timezone information per user (#2472) - #2482

Open
pankaj-basnet wants to merge 19 commits into
wger-project:masterfrom
pankaj-basnet:feat/user-timezone-2472
Open

feat(core): store timezone information per user (#2472)#2482
pankaj-basnet wants to merge 19 commits into
wger-project:masterfrom
pankaj-basnet:feat/user-timezone-2472

Conversation

@pankaj-basnet

Copy link
Copy Markdown
Contributor

⚠️ Note on Stacked PRs: This branch is built on top of the changes from PR #2422

This PR adds support for storing IANA timezone names on a user's profile and dynamically activating the user's local timezone for incoming requests. This ensures the user's actual local calendar day rather than the server's global TIME_ZONE setting.

Proposed Changes

  1. UserProfile Model (wger/core/models/profile.py):
    • Added a timezone CharField (defaults to settings.TIME_ZONE).
    • Added validate_timezone validator utilizing Python standard library zoneinfo.
    • Added a .zone_info property helper on UserProfile.
  2. Database Migration (wger/core/migrations/):
    • Added migration to add the column
  3. Middleware (wger/core/middleware.py & settings_global.py):
    • Implemented TimezoneMiddleware.
  4. API Serializer (wger/core/api/serializers.py):
    • Exposed timezone on UserProfileSerializer.
  5. Session Model (wger/manager/models/session.py):
    • Updated WorkoutSession.local_day.

📋 Design Decision Log

Question from Issue #2472 Decision Choice
Field Type CharField storing standard IANA name string (e.g. "Europe/Berlin").
Default Value Set to settings.TIME_ZONE at creation time.
Update Mechanism Mobile/web app updates field via user profile API (UserProfileSerializer).
Activation Point Middleware executed after user authentication per request cycle.

Related Issue(s)

Closes #2472

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Code has been formatted to avoid unnecessary diffs (ruff format && isort .)
  • If the feature is big enough or if there are manual steps needed (deployment
    changes etc.), write a small writeup in CHANGELOG.md

Apple and others added 19 commits July 7, 2026 00:36
- Replaced date, time_start, and time_end fields with datetime_start and datetime_end
- Updated logging logic to map workouts crossing midnight correctly
- Adjusted statistics and trophies calculations to use local timezones
- Added data migration to preserve legacy workout dates
- Fixed test suites to support multi-day sessions
…n-datetime

# Conflicts:
#	wger/core/tests/test_user.py
#	wger/gym/helpers.py
#	wger/manager/tests/test_workout_session.py
A log can be pinned to a session of another day through the API. Without
the filter the data migration would move such a session to the day of
its logs, silently shifting streaks and date-based trophies
- add TimezoneMiddleware to activate user timezone per request
- expose timezone field in UserProfileSerializer
- update WorkoutSession.local_day to use user timezone
@rolandgeider

Copy link
Copy Markdown
Member

you never rest, do you? 😄

@pankaj-basnet

Copy link
Copy Markdown
Contributor Author

you never rest, do you? 😄

wger projects repo's are a perfect fit for me 🙌 . i have not done any other project other than django, flutter . now mcp repo is awesome bonus for me 💪🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store timezone information per user

2 participants