Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggregateGroupByPeriod returns error on Android 13&Under #194

Open
Hpaniliale opened this issue Jan 15, 2025 · 2 comments
Open

aggregateGroupByPeriod returns error on Android 13&Under #194

Hpaniliale opened this issue Jan 15, 2025 · 2 comments
Labels
Status: duplicate This issue or pull request already exists Type: bug

Comments

@Hpaniliale
Copy link

Hpaniliale commented Jan 15, 2025

Describe the bug
By using aggregateGroupByPeriod in Android 14 + I didn't have any problems, but when checking on slightly older devices, Android 13 under, I wasn't able to obtain any data from the API and got a Possible Promise error.

To Reproduce
Steps to reproduce the behavior:

  1. set emulator to android 13
  2. run a aggregateGroupByPeriod

Expected behavior
Same as on android 14+ it returns the data inquired for.

Screenshots
Screenshot 2025-01-15 at 13 55 56

Minimal Reproducible
return (await aggregateGroupByPeriod({
recordType: type,
timeRangeFilter: {
operator: 'between',
startTime: androidFormatQueryDate('2024-12-13'),
endTime: androidFormatQueryDate('2025-01-13'),
},
timeRangeSlicer: {
period: 'DAYS',
length: 1,
},
})) as HealthCareAggregationResult;

update
the error happens even with the Example Code on Android 13 and under
const aggregateSampleGroupByPeriod = () => {
aggregateGroupByPeriod({
recordType: 'Steps',
timeRangeFilter: {
operator: 'between',
startTime: getBeginningOfLast7Days().toISOString(),
endTime: now().toISOString(),
},
timeRangeSlicer: {
period: 'DAYS',
length: 1,
},
}).then((result) => {
console.log(
'Aggregated Group by Period: ',
JSON.stringify({ result }, null, 2)
);
});
};

Environment:

  • Health Connect Version: 3.3.1
  • React Native Version: 0.73.9
  • New architecture enabled: No
  • Using Expo: No
  • Android API Level: API 33 (Android 13)
@matinzd matinzd added the Status: duplicate This issue or pull request already exists label Jan 15, 2025
@JoarTaylor
Copy link

Hi ! Any updates on this?

@JoarTaylor
Copy link

JoarTaylor commented Jan 27, 2025

past into patch-package, fixes groupbyperiod

diff --git a/node_modules/react-native-health-connect/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt b/node_modules/react-native-health-connect/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt
index b595ec1..2194058 100644
--- a/node_modules/react-native-health-connect/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt
+++ b/node_modules/react-native-health-connect/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt
@@ -18,6 +18,9 @@ import java.time.ZoneOffset
 import java.time.Duration
 import java.time.Period
 import kotlin.reflect.KClass
+import java.time.LocalDateTime
+import java.time.ZoneId
+
 
 fun <T : Record> convertReactRequestOptionsFromJS(
   recordType: KClass<T>, options: ReadableMap
@@ -89,11 +92,13 @@ fun ReadableMap.getTimeRangeFilter(key: String? = null): TimeRangeFilter {
 
   val operator = timeRangeFilter.getString("operator")
 
-  val startTime =
-    if (timeRangeFilter.hasKey("startTime")) Instant.parse(timeRangeFilter.getString("startTime")) else null
+  val startTime = if (timeRangeFilter.hasKey("startTime")) {
+    LocalDateTime.ofInstant(Instant.parse(timeRangeFilter.getString("startTime")), ZoneId.systemDefault())
+} else null
 
-  val endTime =
-    if (timeRangeFilter.hasKey("endTime")) Instant.parse(timeRangeFilter.getString("endTime")) else null
+val endTime = if (timeRangeFilter.hasKey("endTime")) {
+    LocalDateTime.ofInstant(Instant.parse(timeRangeFilter.getString("endTime")), ZoneId.systemDefault())
+} else null
 
   when (operator) {
     "between" -> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: duplicate This issue or pull request already exists Type: bug
Projects
None yet
Development

No branches or pull requests

3 participants