I added a weekly training-duration comparison to BetterFit's workout recommendation. The question was whether last week's recorded workouts met a target supplied by the caller. The comparison sits alongside the workout, which still comes from the existing recommendation logic. See the BetterFit library change and tests.
The test puts a workout in each of three weeks and asks for a recommendation ten minutes into a new Sunday-start week in Los Angeles. Daylight saving began the previous Sunday, so that calendar week was 167 hours long. A cutoff based on 168 elapsed hours would reach back into Saturday.
| Fixture workout | Recorded duration |
|---|---|
| Saturday in the older week | 90 min |
| Sunday in the previous week | 30 min |
| Sunday in the current week | 45 min |
BetterFit finds the start of the current week, steps back one calendar day, then finds the start of the week containing that day. It uses the same calendar the import used to group workouts. Only the 30-minute summary matches, and it meets the 30-minute target exactly.
The library keeps a measured zero as a valid result below the target. Missing or unusable duration leaves the comparison empty while the workout recommendation remains available. The next step is wiring the comparison into the app.