diff --git a/.gitignore b/.gitignore
index 8a67d03..8350a7f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -368,4 +368,9 @@ gradle-app.setting
**/build/
# End of https://www.toptal.com/developers/gitignore/api/java,gradle,git,intellij,linux,windows,macos,node
-**/target/
\ No newline at end of file
+**/target/
+
+.idea/
+.idea/**
+
+GpxAndroidSdk.iml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d08a310..dc0551c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
GpxAndroidSdk
me.bvn13.sdk.android.gpx
- 1.10-SNAPSHOT
+ 1.10.1-SNAPSHOT
jar
@@ -58,6 +58,11 @@
+
+ org.slf4j
+ slf4j-api
+ 2.0.6
+
org.jetbrains.kotlin
kotlin-test-junit5
@@ -234,7 +239,7 @@
develop
true
- 2
+ 3
diff --git a/src/main/kotlin/me/bvn13/sdk/android/gpx/GpxWriter.kt b/src/main/kotlin/me/bvn13/sdk/android/gpx/GpxWriter.kt
index a4005e9..1dc9085 100644
--- a/src/main/kotlin/me/bvn13/sdk/android/gpx/GpxWriter.kt
+++ b/src/main/kotlin/me/bvn13/sdk/android/gpx/GpxWriter.kt
@@ -82,6 +82,9 @@ import me.bvn13.sdk.android.gpx.GpxConstant.Companion.HEADER
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.SCHEMA_LOCATION
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS_XSI
+import me.bvn13.sdk.android.gpx.GpxWriter.Companion.log
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
import java.time.Clock
import java.time.OffsetDateTime
@@ -257,10 +260,17 @@ fun toXmlString(value: Double?, nodeName: String) = if (value != null) {
""
}
-fun toXmlString(value: OffsetDateTime?, nodeName: String) = if (value != null) {
- "<${nodeName}>${value.format(DTF)}${nodeName}>"
-} else {
- ""
+fun toXmlString(value: OffsetDateTime?, nodeName: String): String {
+ if (value != null) {
+ try {
+ return "<${nodeName}>${value.format(DTF)}${nodeName}>"
+ } catch (e: Exception) {
+ log.warn(String.format("Unable to format datetime value %s in node %s", value, nodeName), e)
+ return ""
+ }
+ } else {
+ return ""
+ }
}
fun toXmlString(value: Map?) = value?.entries?.joinToString(separator = "") {
@@ -280,5 +290,6 @@ class GpxWriter {
const val XMLNS = "http://www.topografix.com/GPX/1/1"
const val XMLNS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
const val SCHEMA_LOCATION = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
+ val log: Logger = LoggerFactory.getLogger(GpxWriter.javaClass)
}
}