Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-1026

Joda, JSR-310 and ThreeTenBp converters are timezone-sensitive

    XMLWordPrintable

    Details

      Description

      if saved object contains LocalDate(Time) fields, and is read on the server with different timezone than on server that did the save, such field will have different values on two servers.
      This is OK for java.util.Date, or DateTime, because in terms of Epoch values are equal, but in case of LocalDate(Time) there's no way to compensate TZ (this information is lost), or even detect such situation.
      I didn't have a chance to check it with java.time.* classes, but I suspect it is broken in similar way.

      My (temporary?) solution was to write custom converters which adds/subtracts current TZ offset to compensate java.util.Date TZ.

      @Test
          public void testLocalDateVsDateIssue() {
              TestUtils.setTimeZone("GMT-1");
              FakeContentItem fake = new FakeContentItem();
              fake.setLocalDateTime(new LocalDateTime(2014, 8, 1, 12, 0, 0));
              mongo.save(fake);
              TestUtils.setTimeZone("GMT+1");
              FakeContentItem fake2 = mongo.findById(fake.getUid(), FakeContentItem.class);
              assertThat(fake2.getLocalDateTime(), equalTo(fake.getLocalDateTime())); 
      //Expected: <2014-08-01T12:00:00.000> but: was <2014-08-01T14:00:00.000>
          }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mp911de Mark Paluch
              Reporter:
              pijmleko Kris Zawadzki
              Last updater:
              Mark Paluch
              Votes:
              4 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: