react-native-health-connect
react-native-health-connect copied to clipboard
`Duration must be set with physical times` error for aggregateGroupByPeriod on Anroid 13 and below
When I call aggregateGroupByPeriod function on Android 13 and below, I do get the following error:
Duration must be set with physical times
const test = await aggregateGroupByPeriod({
recordType: 'Steps',
timeRangeFilter: {
operator: 'between',
startTime: new Date('2024-10-11').toISOString(),
endTime: new Date('2024-10-15').toISOString(),
},
timeRangeSlicer: {
period: 'DAYS',
duration: 1,
},
});
**Environment:**
- Health Connect Version: 3.2.1
- React Native Version: 0.73.6
- Using Expo: Dev Client
- Android API Level: API 33 (Android 13)
This might be related to https://stackoverflow.com/a/74468785/7978635.
I might need to refactor the code to use LocalDateTime instead of Instant.
https://developer.android.com/health-and-fitness/guides/health-connect/develop/aggregate-data#duration
@matinzd Hey! Could you let me know when you approximately plan to fix this bug and release an update?
Hoping for a fix soon too!
I can't promise until I find some free time. I am also working full-time and I am not paid to do work here.
I can't promise until I find some free time. I am also working full-time and I am not paid to do work here.
Fully understandable, thanks for all the work so far!
Hi Matin, we are willing to help (our devs) or fix the 'not paid'-part to fix this for the community. Just let us know.
Getting the same issue on Android 13 and lower. Works fine with Android 14. I'm using dayjs for date time:
return await aggregateGroupByPeriod({ recordType: 'Steps', timeRangeFilter: { operator: 'between', startTime: dayjs(startDate).toISOString(), endTime: dayjs(endDate).toISOString(), }, timeRangeSlicer: { period: 'DAYS', length: 1, }, });
This needs to be fixed in the native code when I find some time. You only need to send ISO format. No special thing is needed on JS side.