matinzd / react-native-health-connect

React native library for health connect (Android only)
http://matinzd.github.io/react-native-health-connect
MIT License
233 stars 43 forks source link

Feature Request: Include timezone information in SleepStage #179

Open kyurikotpq opened 6 days ago

kyurikotpq commented 6 days ago

Thank you so much for developing this package 🙏

Describe the bug Currently, sleep sessions and sleep stages are returned in UTC strings without timezone information:

// Example SleepStage object
{
    "stage": 4,
    "endTime": "2024-11-08T11:24:00Z",
    "startTime": "2024-11-08T11:05:00Z"
}

Timezone information is crucial because the user might travel (and thus change timezones) frequently. Without timezone offset information, records before the timezone change will always be interpreted in the device's current timezone (i.e. after the user has travelled), leading to inaccurate reporting. Things also get tricky with daylight savings if timezone offset isn't accounted for.

To Reproduce Steps to reproduce the behavior:

  1. Use the readRecords() function, especially for SleepSession.
  2. startTime and endTime is returned in UTC strings without timezone offset information

Expected behavior
Include ZoneOffset object, similar to startZoneOffset and endZoneOffset available in ExerciseSessionRecord

// node_modules/react-native-health-connect/src/types/base.types.ts
export interface SleepStage {
  startTime: string;
  endTime: string;
  // Use SleepStageType constant
  stage: number;

  // Requested feature
  startZoneOffset?: ZoneOffset;
  endZoneOffset?: ZoneOffset;
}

Environment: