Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zoneOffset to ExerciseSessionRecord results #126

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
matinzd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl<ExerciseSessionRecord>
override fun parseRecord(record: ExerciseSessionRecord): WritableNativeMap {
return WritableNativeMap().apply {
putString("startTime", record.startTime.toString())
putMap("startZoneOffset", zoneOffsetToJsMap(record.startZoneOffset))
putString("endTime", record.endTime.toString())
putMap("endZoneOffset", zoneOffsetToJsMap(record.endZoneOffset))
putString("notes", record.notes)
putString("title", record.title)
putInt("exerciseType", record.exerciseType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.facebook.react.bridge.WritableNativeArray
import com.facebook.react.bridge.WritableNativeMap
import dev.matinzd.healthconnect.records.*
import java.time.Instant
import java.time.ZoneOffset
import kotlin.reflect.KClass

fun <T : Record> convertReactRequestOptionsFromJS(
Expand Down Expand Up @@ -258,6 +259,17 @@ fun lengthToJsMap(length: Length?): WritableNativeMap {
}
}

fun zoneOffsetToJsMap(zoneOffset: ZoneOffset?): WritableNativeMap? {
if (zoneOffset == null) {
return null
}

return WritableNativeMap().apply {
putString("id", zoneOffset.id)
putInt("totalSeconds", zoneOffset.totalSeconds)
}
}

fun getVolumeFromJsMap(volume: ReadableMap?): Volume {
if (volume == null) {
throw InvalidLength()
Expand Down
8 changes: 5 additions & 3 deletions src/types/base.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ export interface BaseRecord {
metadata?: Metadata;
}

export interface ZoneOffset {
id: string;
totalSeconds: number;
}

export interface InstantaneousRecord extends BaseRecord {
time: string;
zoneOffset?: string;
}

export interface IntervalRecord extends BaseRecord {
startTime: string;
startZoneOffset?: string;
endTime: string;
endZoneOffset?: string;
}

export interface Metadata {
Expand Down
3 changes: 3 additions & 0 deletions src/types/records.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
ExerciseLap,
SleepStage,
ExerciseRoute,
ZoneOffset,
} from './base.types';

export interface ActiveCaloriesBurnedRecord extends IntervalRecord {
Expand Down Expand Up @@ -100,6 +101,8 @@ export interface ElevationGainedRecord extends IntervalRecord {
}

export interface ExerciseSessionRecord extends IntervalRecord {
startZoneOffset?: ZoneOffset;
endZoneOffset?: ZoneOffset;
recordType: 'ExerciseSession';
// Use ExerciseType constant
exerciseType: number;
Expand Down
Loading