Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to count steps for an exercise that continues after midnight?

Currently, my app reports the total steps for a period from userActivity.today.adjusted["steps"]. I record the initial value and subtract it from the end value to get the total steps taken during the activity. I've been struggling to figure out how to make this work if someone starts an activity before midnight and completes it after. The userActivity.today.adjusted["steps"] resets to zero at midnight and I tried userActivity.yesterday.adjusted["steps"] but userActivity.yesterday is undefined. Is there an easy way to pull yesterday's totals? My plan B is to save and update max steps until steps is less than max steps (indicating the day changed).

Best Answer
0 Votes
2 REPLIES 2

Perhaps not an easy way, but have a look at dayHistory.

Peter McLennan
Gondwana Software
Best Answer

Thanks! I was able to pull yesterday's data with:

let dayRecords = dayHistory.query();
let stepsYesterday = dayRecords[0].steps;
Best Answer