Skip to content

Fix: Refactor WorkoutSession to support overnight workouts (#2379) - #2422

Open
deepu4402020 wants to merge 3 commits into
wger-project:masterfrom
deepu4402020:fix-midnight-session-datetime
Open

Fix: Refactor WorkoutSession to support overnight workouts (#2379)#2422
deepu4402020 wants to merge 3 commits into
wger-project:masterfrom
deepu4402020:fix-midnight-session-datetime

Conversation

@deepu4402020

Copy link
Copy Markdown

Proposed Changes

As discussed in the issue with @rolandgeider and @DunklerPhoenix, this PR implements the proposed backend refactor for Workout Sessions:

  • Replaced legacy date, time_start, and time_end fields in WorkoutSession with datetime_start and datetime_end to fully support multi-day and overnight workouts natively.
  • Removed the unique_together constraint to support multiple discrete sessions/workouts per day (e.g., morning cardio, evening gym).
  • Introduced a configurable MAX_SESSION_LENGTH_HOURS (set to 12h, taking the middle ground for long activities like hiking).
  • Updated the WorkoutLog logic to follow the exact session-matching priority order outlined by the maintainers.
  • Adjusted statistics and trophies calculations to correctly project the UTC timestamp into local timezones to prevent day-shift bugs.
  • Added a custom data migration to safely preserve legacy user workout dates into the new schema.
  • Fixed the manager and trophies test suites to support the new multi-day session data structures.

Related Issue(s)

Fixes #2379

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 added 3 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
@deepu4402020

Copy link
Copy Markdown
Author

Hi @rolandgeider ,

Just following up on this PR whenever you have time.

Could you please let me know if there are any changes needed or if there's anything blocking the review? I'd be happy to update it.

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Training over night breaks routine into two

1 participant