krokyze / FitKit

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.
BSD 2-Clause "Simplified" License
98 stars 72 forks source link

[Bug] FitKit iOS will ignore data in the same hour. #30

Closed SheriefAlaa closed 4 years ago

SheriefAlaa commented 4 years ago

Hey,

I think I may have hit a bug.

How to reproduce: 1- create 3 walking/running/distance activities in a span of an hour. Let's say 11/11/2019 11:00:00PM to 12:00:00PM 2- The first activity will have a start date 11/11/2019 11:00:00PM UTC end date 11/11/2019 11:15:00PM UTC 3- The second activity will have a start date 11/11/2019 11:16:00PM UTC end date 11/11/2019 11:32:00PM UTC 4- The third activity will have a start date 11/11/2019 11:40:00PM UTC end date 11/11/2019 11:50:00PM UTC 5- Query using FitKit.read(DataType.DISTANCE, dateFrom: DateTime.parse("11/11/2019 11:39:00"), dateTo: DateTime.now().toUtc()); 6- See how the query returns 0 results.

Any help would be much much appreciated. Thanks.

SheriefAlaa commented 4 years ago

All dates are in UTC. I even generated dates at server side and passed them to fitkit and it somehow doesn't fetch specific activities within an hour range.

krokyze commented 4 years ago

Hey @SheriefAlaa did you found out what's the issue?

SheriefAlaa commented 4 years ago

Hey @SheriefAlaa did you found out what's the issue?

Not in an optimal way. After digging deep into the Swift/Android code of the plugin, I have discovered that calling read with from/to dates that include timezone info is pretty useless because the plugin will not care about this since it uses Unix epochs.

What was a even bigger surprise that returned data dates were in local device time that did not carry timezone info too which in the end forced me to save dates without timezone.

Maybe there should be a line in the readme that warns users about this?

Thank you.

SheriefAlaa commented 4 years ago

@krokyze ^

krokyze commented 4 years ago

@SheriefAlaa unix epochs are timezone independent so calling read with from/to dates that include timezone info is not useless. Also returned DateTime is in local device time with timezone included.

The issue in your query is that for DateTime.parse("11/11/2019 11:39:00") you didn't add UTC time zone like this "11/11/2019 11:39:00z".