Skip to content

Commit

Permalink
ExerciseViewer TopoGrafixGpxParser: bugfix for issue #260
Browse files Browse the repository at this point in the history
- added support for timestamps with timezone / offset info
  • Loading branch information
ssaring committed Sep 1, 2023
1 parent 3e1adf8 commit bacf7ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 2 additions & 0 deletions sportstracker/docs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ v8.0.0:
(when the lap contains just a break without any activity)
- All XML-based parsers (GPX, TCX, Polar): fixed error when opening files with
spaces or special characters in the filename
- GPX parser (TopoGrafixGpxParser): bugfix for issue #260
- support for GPX files where timestamps contain timezone / offset info

v7.9.1:
Project changes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class TopoGrafixGpxParser : AbstractExerciseParser() {
* Calculates the speed summary (only when samples contain timestamps, from which speed is derived).
*/
private fun calculateSpeedSummary(exercise: EVExercise) {
if (!exercise.sampleList.isEmpty()) {
if (exercise.sampleList.isNotEmpty()) {

val speedMax = exercise.sampleList
.map { it.speed!! }
Expand All @@ -292,21 +292,16 @@ class TopoGrafixGpxParser : AbstractExerciseParser() {
val sampleHeartrates:List<Short> = exercise.sampleList
.mapNotNull { it.heartRate }

if (!sampleHeartrates.isEmpty()) {
if (sampleHeartrates.isNotEmpty()) {
exercise.heartRateAVG = sampleHeartrates.average().roundToInt().toShort()
exercise.heartRateMax = sampleHeartrates.maxOrNull()
}
}

/**
* Parses the date time in ISO format specified in the passed text and returns the appropriate LocalDateTime.
* Parses the specified date time in ISO format and returns the appropriate LocalDateTime.
*/
private fun parseDateTime(dateTimeText: String): LocalDateTime {
// remove the suffix 'Z' if contained in the passed text, can't be ignored by ISO_LOCAL_DATE_TIME
val dateTimeTextFixed = if (dateTimeText.endsWith('Z'))
dateTimeText.substring(0, dateTimeText.length - 1)
else
dateTimeText
return LocalDateTime.parse(dateTimeTextFixed, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
return LocalDateTime.parse(dateTimeText, DateTimeFormatter.ISO_DATE_TIME)
}
}

0 comments on commit bacf7ec

Please sign in to comment.