Reputation: 73
What is the timezone in which the current steps are calculated in healthKit? Is it UTC or the device timezone? What if the user changes timezones? How will it impact the healthkit data?
Upvotes: 4
Views: 1430
Reputation: 12015
The startDate
and endDate
of HKSample objects are NSDate values, and thus contain no time zone information (see the overview of NSDate documentation for more info). Technically I wouldn't say that NSDate values are UTC dates, but you can think of them that way.
This means that, looking at just the startDate/endDate of a sample, you cannot tell what the local time was for the user when the sample was recorded. For example, if the user has moved around across time zones, you may not be able to determine whether a sample was actually recorded 11:30 pm Friday local time or 12:30 am Saturday in some other location.
There is a standard key HKMetadataKeyTimeZone
that can be used to store the original time zone in sample's metadata
dictionary. This would give you exactly the information you need, but you can't rely on it actually being present. Apple doesn't even populate the time zone metadata for health data recorded natively by the iPhone or Apple Watch (see this Stack Overflow post for further discussion).
Upvotes: 4