Skip to content

Commit

Permalink
remove kmongo.oldLocalBehaviour flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzago committed Aug 14, 2017
1 parent 265a73b commit 2bd3458
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,13 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.OffsetTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZoneOffset.UTC
import java.time.ZonedDateTime
import java.util.Date


internal class BsonModule : SimpleModule() {

companion object {
//TODO remove this in kmongo 3.5
private val oldZoneIdBehaviour = System.getProperty("kmongo.oldLocalBehaviour") != null
val mongoZoneId: ZoneId get() = if (oldZoneIdBehaviour) ZoneId.systemDefault() else ZoneOffset.UTC
}

private object ObjectIdBsonSerializer : JsonSerializer<ObjectId>() {

override fun serialize(objectId: ObjectId, gen: JsonGenerator, serializerProvider: SerializerProvider) {
Expand Down Expand Up @@ -268,19 +261,19 @@ internal class BsonModule : SimpleModule() {
private object ZonedDateTimeBsonDeserializer : TemporalBsonDeserializer<ZonedDateTime>() {

override fun toObject(date: Date): ZonedDateTime
= ZonedDateTime.ofInstant(date.toInstant(), mongoZoneId)
= ZonedDateTime.ofInstant(date.toInstant(), UTC)
}

private object OffsetDateTimeBsonDeserializer : TemporalBsonDeserializer<OffsetDateTime>() {

override fun toObject(date: Date): OffsetDateTime
= OffsetDateTime.ofInstant(date.toInstant(), mongoZoneId)
= OffsetDateTime.ofInstant(date.toInstant(), UTC)
}

private object LocalDateTimeBsonDeserializer : TemporalBsonDeserializer<LocalDateTime>() {

override fun toObject(date: Date): LocalDateTime
= LocalDateTime.ofInstant(date.toInstant(), mongoZoneId)
= LocalDateTime.ofInstant(date.toInstant(), UTC)
}

private object LocalDateBsonDeserializer : TemporalBsonDeserializer<LocalDate>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import org.bson.types.Binary
import org.bson.types.MaxKey
import org.bson.types.MinKey
import org.bson.types.ObjectId
import org.litote.kmongo.jackson.BsonModule.Companion.mongoZoneId
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.OffsetTime
import java.time.ZoneOffset.UTC
import java.time.ZonedDateTime
import java.util.Calendar
import java.util.Date
Expand Down Expand Up @@ -130,13 +130,13 @@ internal class ExtendedJsonModule : SimpleModule() {
internal object LocalDateExtendedJsonSerializer : TemporalExtendedJsonSerializer<LocalDate>() {

override fun epochMillis(temporal: LocalDate): Long
= ZonedDateTimeExtendedJsonSerializer.epochMillis(temporal.atStartOfDay(mongoZoneId))
= ZonedDateTimeExtendedJsonSerializer.epochMillis(temporal.atStartOfDay(UTC))
}

internal object LocalDateTimeExtendedJsonSerializer : TemporalExtendedJsonSerializer<LocalDateTime>() {

override fun epochMillis(temporal: LocalDateTime): Long
= ZonedDateTimeExtendedJsonSerializer.epochMillis(temporal.atZone(mongoZoneId))
= ZonedDateTimeExtendedJsonSerializer.epochMillis(temporal.atZone(UTC))
}

internal object LocalTimeExtendedJsonSerializer : TemporalExtendedJsonSerializer<LocalTime>() {
Expand Down

0 comments on commit 2bd3458

Please sign in to comment.