react-native-health-connect icon indicating copy to clipboard operation
react-native-health-connect copied to clipboard

`Duration must be set with physical times` error for aggregateGroupByPeriod on Anroid 13 and below

Open Gytjarek opened this issue 1 year ago • 8 comments

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)

Gytjarek avatar Oct 23 '24 14:10 Gytjarek

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 avatar Nov 19 '24 20:11 matinzd

@matinzd Hey! Could you let me know when you approximately plan to fix this bug and release an update?

Gytjarek avatar Dec 02 '24 16:12 Gytjarek

Hoping for a fix soon too!

sjaakbanaan avatar Dec 03 '24 08:12 sjaakbanaan

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.

matinzd avatar Dec 03 '24 12:12 matinzd

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!

sjaakbanaan avatar Dec 03 '24 13:12 sjaakbanaan

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.

fitterup avatar Dec 23 '24 08:12 fitterup

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, }, });

RonanMaguire avatar Jan 30 '25 09:01 RonanMaguire

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.

matinzd avatar Jan 31 '25 09:01 matinzd