orlandos-nl / BSON

Native Swift library for BSON (http://bsonspec.org)
https://orlandos.nl/docs/mongokitten/articles/bson
MIT License
108 stars 36 forks source link

Date decoding strategy #82

Closed surajthomask closed 5 months ago

surajthomask commented 5 months ago

Hi Joannis,

I have pushed couple of commits which can address the issue with timestamp to date conversion introduced in version 8.0.2.

A short description of the issue is that, pre-8.0.2, the date objects were being pushed into MongoDB as time interval from reference date (2000), but the 8.0.2 started to decode them as time interval from 1970.

If we can add a configuration to continue parsing the date fields as from time interval since 2000, we will be able to avoid a painful data migration on our existing production data.

Please have a look, and see if you have any other suggestions to address this in any other way.

Warm regards, Suraj

surajthomask commented 5 months ago

@Joannis I have added unit tests for the date decoding. I have updated the default decoding strategy to reference date relative. This is because prior to 8.0.2, the dates were all relative to reference date. In 8.0.2, the decoding was changed to relative to unix epoch, but writing to DB is done as primitive. So I do not see any impact on any of the servers which adopted the version 8.0.2 on changing the default value. The only flow where this strategy will be considered is for data that was inserted by pre-8.0.2 library and that will logically and correctly convert the value using reference date. Please let me know your thoughts on this.