Fix: Allow overnight workouts and prevent session splitting (#2379) - #2397
Open
prkhrexists wants to merge 1 commit into
Open
Fix: Allow overnight workouts and prevent session splitting (#2379)#2397prkhrexists wants to merge 1 commit into
prkhrexists wants to merge 1 commit into
Conversation
…ject#2379)\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
Thanks for the PR! I still need to think if this is the right approach, or if we shouldn't refactor how we handle logs and sessions (e.g. changing the start and end fields to proper datetimes would make the "end not before start" also work across day boundaries. Also all the "magic" we have when saving logs). In any case I'm adding the issue to the next release so it doesn't get lost |
Author
|
I would love to contribute to the refactoring approach you mentioned. Could you elaborate a bit more on the proposed solution so I can get started? |
Member
|
@prkhrexists alright, I have added some ideas to the original issue. See if they make sense to you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves the overnight workout bug where sessions crossing midnight trigger validation errors and get split into two separate logs.
Changes Made:
session.py: Updated WorkoutSession.clean(). Valid overnight sessions (e.g., 23:00 → 01:00) now pass validation. To prevent absurd spans (e.g., AM/PM typos), overnight durations are calculated and capped at a maximum of 12 hours. Removed a dead import to maintain linting standards.
log.py: Updated WorkoutLog.save(). Removed reliance on wall-clock times. When a new log is created, the logic now checks the latest session state for that user/routine. It only shifts the new log back by one day if the latest session is from yesterday, explicitly overnight (start > end), or still active (start set, end empty).
Tests: Added regression tests to cover the anchored overnight session cases.
Fixes #2379