[JAVA-3336] Date is not fetched as it is stored - possible Reader problem? Created: 26/Jun/19 Updated: 27/Oct/23 Resolved: 26/Jun/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 3.10.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Dario Nuevo | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MongoDB v3.6.5 openjdk version "1.8.0_212" Linux 5.0.0-17-generic #18-Ubuntu SMP Tue Jun 4 15:34:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux |
||
| Attachments: |
|
| Description |
|
Hi guys.. We are using the driver in an ETL project that converts dates. I'm a bit puzzled with this behavior. We inserted this record:
The problem is with the "createDate" field - as you see it's 1245-04-28T13:27:32.000Z Later in the application (well, in our integration tests), i fetch the entity back:
I get this: So what I see saved in MongoDB is ISODate("1245-04-28T13:27:32.000Z") - I get back "Fri Apr 21 13:27:32 UTC 1245" - somehow 7 days were lost? Sadly I lack the ability to really diagnostic this problem - I see that the BSON reader gets the value "-23973085975000" in readInt64() for the specific datetime. This indeed is the rendered Date (April 21).. Which is strange as mongo shell shows me April 28 (which is what I inserted).. Any ideas what could be wrong? Thank you so much! |
| Comments |
| Comment by Dario Nuevo [ 26/Jun/19 ] | |||||
|
@ross.lawley OK; appreciate your input! thanks! | |||||
| Comment by Ross Lawley [ 26/Jun/19 ] | |||||
|
Hi dario.nuevo, Thanks for the ticket. Unfortunately, there are many issues with Java Date class and this shows an issue crossing calendars. Prior to 1582 Date will use the Julian calendar and after it will use the Gregorian - What you are seeing is differences in date representations between these calendars. Happily, the underlying data is stored in MongoDB as ms since epoch and when using Java Instant classes (which always use the Gregorian calendar) it will correct itself:
Just to let you know for future reference the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a broader audience there. If your business requires an answer from MongoDB within a time frame then we do offer production support. I hope that helps, Ross |