OvalMoney / react-native-fitness

A React Native module to interact with Apple Healthkit and Google Fit.
MIT License
343 stars 68 forks source link

hour interval not working on Android #57

Closed rlems closed 4 years ago

rlems commented 4 years ago

I'm trying to get the steps in hours. It works for iOS, but not for Android devices. On Android it still returns the steps per day for me. If I manually alter the node_modules/@ovalmoney/react-native-fitness/android/src/main/java/com/ovalmoney/fitness/manager/Manager.java and set

interval = TimeUnit.HOURS;

it does work.

This is my code:

function getSteps(startDate, endDate, interval = 'hour') {
  return Fitness.getSteps({ startDate, endDate, interval })
    .catch(e => {
      console.error('getSteps error', e);
    });
}

And I call this function like this:

const res = await getSteps(startDate, endDate);

The resulting value of res is

[
  { quantity: 815, endDate: "2020-05-27T23:16:07.643+0200", startDate: "2020-05-27T07:17:11.227+0200" },
  { quantity: 8808, endDate: "2020-05-29T00:00:00.000+0200", startDate: "2020-05-28T07:34:28.192+0200" },
  { quantity: 1802, endDate: "2020-05-29T23:31:36.275+0200", startDate: "2020-05-29T00:00:00.000+0200" },
  { quantity: 1128, endDate: "2020-05-30T23:47:59.406+0200", startDate: "2020-05-30T00:28:58.019+0200" },
  { quantity: 1109, endDate: "2020-05-31T21:26:37.564+0200", startDate: "2020-05-31T00:40:05.296+0200" },
  { quantity: 393, endDate: "2020-06-01T23:00:21.904+0200", startDate: "2020-06-01T01:41:36.727+0200" },
  { quantity: 333, endDate: "2020-06-02T10:52:22.654+0200", startDate: "2020-06-02T07:12:06.461+0200" }
]

Any idea why this is happening?

Francesco-Voto commented 4 years ago

Hi @rlems , I will check it

rlems commented 4 years ago

Hi @rlems , I will check it

Thank you. Haven't found why this is happening yet.

rlems commented 4 years ago

@Francesco-Voto I think I've found the issue.

The customInterval value passed to getSteps is a String object and in the code it's compared to another String. 2 string objects are never the same by '==' comparison, see also https://www.geeksforgeeks.org/difference-equals-method-java/ Using .isEqual() method would solve the problem.

I'll see if I can solve the problem and open a PR

Francesco-Voto commented 4 years ago

Thank you @rlems ! I close it