@interval-health/capacitor-health 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1366,6 +1366,12 @@ final class Health {
1366
1366
  private func processMobilityData(startDate: Date, endDate: Date, completion: @escaping (Result<[[String: Any]], Error>) -> Void) {
1367
1367
  let calendar = Calendar.current
1368
1368
 
1369
+ // Calculate the local date range that corresponds to the input UTC date range
1370
+ let startDateComponents = calendar.dateComponents([.year, .month, .day], from: startDate)
1371
+ let endDateComponents = calendar.dateComponents([.year, .month, .day], from: endDate)
1372
+ let localStartDateString = String(format: "%04d-%02d-%02d", startDateComponents.year!, startDateComponents.month!, startDateComponents.day!)
1373
+ let localEndDateString = String(format: "%04d-%02d-%02d", endDateComponents.year!, endDateComponents.month!, endDateComponents.day!)
1374
+
1369
1375
  // Define all mobility quantity types
1370
1376
  let mobilityTypes: [(HKQuantityTypeIdentifier, String)] = [
1371
1377
  (.walkingSpeed, "walkingSpeed"),
@@ -1505,10 +1511,15 @@ final class Health {
1505
1511
  allDates.formUnion(stairSpeedMap.keys)
1506
1512
  allDates.formUnion(sixMinWalkMap.keys)
1507
1513
 
1514
+ // Filter dates to only include those within the requested local date range
1515
+ let filteredDates = allDates.filter { date in
1516
+ return date >= localStartDateString && date <= localEndDateString
1517
+ }
1518
+
1508
1519
  // Create mobility data array with aggregated daily averages
1509
1520
  var mobilityData: [[String: Any]] = []
1510
1521
 
1511
- for date in allDates.sorted() {
1522
+ for date in filteredDates.sorted() {
1512
1523
  var result: [String: Any] = ["date": date]
1513
1524
 
1514
1525
  // Average all measurements for the day
@@ -1556,6 +1567,13 @@ final class Health {
1556
1567
  let group = DispatchGroup()
1557
1568
  let lock = NSLock()
1558
1569
 
1570
+ // Calculate the local date range that corresponds to the input UTC date range
1571
+ // This ensures we only return data for dates that fall within the requested range
1572
+ let startDateComponents = calendar.dateComponents([.year, .month, .day], from: startDate)
1573
+ let endDateComponents = calendar.dateComponents([.year, .month, .day], from: endDate)
1574
+ let localStartDateString = String(format: "%04d-%02d-%02d", startDateComponents.year!, startDateComponents.month!, startDateComponents.day!)
1575
+ let localEndDateString = String(format: "%04d-%02d-%02d", endDateComponents.year!, endDateComponents.month!, endDateComponents.day!)
1576
+
1559
1577
  // Maps to store values by date for each metric
1560
1578
  var stepsMap: [String: Double] = [:]
1561
1579
  var distanceMap: [String: Double] = [:]
@@ -1769,8 +1787,14 @@ final class Health {
1769
1787
  allDates.formUnion(exerciseMinutesMap.keys)
1770
1788
  allDates.formUnion(standHoursMap.keys)
1771
1789
 
1790
+ // Filter dates to only include those within the requested local date range
1791
+ // This prevents returning data from dates outside the user's intended range
1792
+ let filteredDates = allDates.filter { date in
1793
+ return date >= localStartDateString && date <= localEndDateString
1794
+ }
1795
+
1772
1796
  // Create activity data array matching the reference format
1773
- let activityData: [[String: Any]] = allDates.sorted().compactMap { date in
1797
+ let activityData: [[String: Any]] = filteredDates.sorted().compactMap { date in
1774
1798
  var result: [String: Any] = ["date": date]
1775
1799
 
1776
1800
  // Add each metric if available, with proper rounding
@@ -1812,6 +1836,12 @@ final class Health {
1812
1836
  let group = DispatchGroup()
1813
1837
  let lock = NSLock()
1814
1838
 
1839
+ // Calculate the local date range that corresponds to the input UTC date range
1840
+ let startDateComponents = calendar.dateComponents([.year, .month, .day], from: startDate)
1841
+ let endDateComponents = calendar.dateComponents([.year, .month, .day], from: endDate)
1842
+ let localStartDateString = String(format: "%04d-%02d-%02d", startDateComponents.year!, startDateComponents.month!, startDateComponents.day!)
1843
+ let localEndDateString = String(format: "%04d-%02d-%02d", endDateComponents.year!, endDateComponents.month!, endDateComponents.day!)
1844
+
1815
1845
  // Maps to store values by date for each metric
1816
1846
  struct HeartRateStats {
1817
1847
  var sum: Double = 0
@@ -2040,8 +2070,13 @@ final class Health {
2040
2070
  allDates.formUnion(spo2Map.keys)
2041
2071
  allDates.formUnion(respirationRateMap.keys)
2042
2072
 
2073
+ // Filter dates to only include those within the requested local date range
2074
+ let filteredDates = allDates.filter { date in
2075
+ return date >= localStartDateString && date <= localEndDateString
2076
+ }
2077
+
2043
2078
  // Create heart data array matching the TypeScript format
2044
- let heartData: [[String: Any]] = allDates.sorted().compactMap { date in
2079
+ let heartData: [[String: Any]] = filteredDates.sorted().compactMap { date in
2045
2080
  var result: [String: Any] = ["date": date]
2046
2081
 
2047
2082
  // Heart Rate (avg, min, max, count)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interval-health/capacitor-health",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Capacitor plugin to interact with data from Apple HealthKit and Health Connect",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",