OvalMoney / react-native-fitness

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

Not getting Steps data of present day (today) correctly. #53

Closed gypsicoder closed 4 years ago

gypsicoder commented 4 years ago

I am trying to get steps data in android. In google fit I have the following steps data: May 3, 2020 : 124 Steps May 4, 2020: 3958 Steps May 5, 2020: 61 Steps When I am trying to get the data of May 3 to May 5 with startDate 2020-05-03 and endDate 2020-05-05 I am getting following data [ { quantity: 123, │ endDate: '2020-05-04T04:11:07.402+0600', │ startDate: '2020-05-03T09:10:01.770+0600' }, │ { quantity: 4012, │ endDate: '2020-05-05T02:27:37.798+0600', └ startDate: '2020-05-04T11:59:28.624+0600' } ]

Is there anything regarding timezone?

Francesco-Voto commented 4 years ago

Hi @gypsicoder, I guess it can be something relative to the timezone, probably you should pass it on the request. Do you have some news about it?

gypsicoder commented 4 years ago

@Francesco-Voto thank you for your message. I forgot to close the issue. I think I have found the solution. Yes, I think there is some problem regarding time zone or something. I have been able to get the data for the current date successfully with the following codes.

let currentDate = new Date();
let end = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 23, 59, 59);
let start = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
let formattedStartDate = start.toString();
let formattedEndDate = end.toString();
let stepsResult = await Fitness.getSteps({
    startDate: formattedStartDate, 
        endDate: formattedEndDate,
    interval: "days",
});