Skip to content

Commit

Permalink
Update LocalDateTimeTypeAdapter.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Puvikaran2001 committed May 10, 2024
1 parent 0014803 commit c400d6c
Showing 1 changed file with 0 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dk.scheduling.schedulingfrontend.api.typeadapters

import android.util.Log
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
Expand All @@ -26,18 +25,12 @@ class LocalDateTimeTypeAdapter :
typeOfSrc: Type,
context: JsonSerializationContext,
): JsonElement {
Log.i("LocalDateTimeTypeAdapter", "serialize - Input datetime: $datetime")
val output =
ZonedDateTime.ofInstant(
datetime.atZone(ZoneId.systemDefault()).toInstant(),
ZoneId.of("UTC"),
).toLocalDateTime().atZone(ZoneOffset.UTC).format(formatter)

Log.i(
"LocalDateTimeTypeAdapter",
"serialize - Output datetime: $output",
)

return JsonPrimitive(output)
}

Expand All @@ -48,8 +41,6 @@ class LocalDateTimeTypeAdapter :
context: JsonDeserializationContext,
): LocalDateTime {
val utc = Instant.parse(json.asString)
Log.i("LocalDateTimeTypeAdapter", "deserialize - Input datetime: $utc")
Log.i("LocalDateTimeTypeAdapter", "deserialize - Output datetime: ${utc.atZone(ZoneId.systemDefault()).toLocalDateTime()}")
return utc.atZone(ZoneId.systemDefault()).toLocalDateTime()
}
}

0 comments on commit c400d6c

Please sign in to comment.