kmongo
kmongo copied to clipboard
Improve Date storage using Kmongo
I tried to use LocalDateTime as attribute type of an entity. After I saved this entity to mongo, the date field was translated to ISO date, which seems "right" in string form, but in fact beyond of actual epoch timestamp by 8 hours(cause my time zone is UTC+8). Was this expected behaviour?
Yes, this is the current expected behaviour. Mongo has no notion of timezone is their date field, so all date types are converted to UTC before serialization and from UTC after deserialization.
I agree that it is not ideal, especially for LocalDateTime, LocalDate & LocalTime. I let this issue open in order to provide an option to:
- store Local* with the local part in mongo
- add also a zone storage for ZonedDateTime, OffsetDateTime, etc.
Workaround : just override the serializer & deserializer for the types you use to get the expected behaviour.
See also ZonedDateTime