JiBX
  1. JiBX
  2. JIBX-209

serializeDate and deserializeDate are one day off

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: JiBX 1.1.5
    • Fix Version/s: JiBX 1.1.6
    • Component/s: core
    • Labels:
      None
    • Number of attachments :
      1

      Description

      When using the Date serializer/deserializer:

      <format type="java.util.Date" deserializer="org.jibx.runtime.Utility.deserializeDate" serializer="org.jibx.runtime.Utility.serializeDate"/>

      it is actually one day off. When deserializing a date, it subtracts a day and when serializing it adds a day. Attached is example code of this, but basically the problem is on line 652 of Utility.java:

      long day = parseDigits(text, split+4, 2) - 1;

      which converts 2008/03/11 to 2008/03/10. It looks like it will also add a day when deserializing it (line 1121 of Utility.java) :

      int day = (int)(extra / MSPERDAY) + 1;

      The attached code is a modified version of the starter application to include a date and throws an exception if the date is a day off.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        I've tried this test case with the current code, and it ran without a problem. However, the date conversion used will not necessarily work as this test code expects with java.util.Calendar - the conversion sets the time values correctly for UTC, while Calendar by default uses the local time zone information. I'll add Javadoc comments to these conversion methods to make this clear.

        Show
        Dennis Sosnoski added a comment - I've tried this test case with the current code, and it ran without a problem. However, the date conversion used will not necessarily work as this test code expects with java.util.Calendar - the conversion sets the time values correctly for UTC, while Calendar by default uses the local time zone information. I'll add Javadoc comments to these conversion methods to make this clear.
        Hide
        Dennis Sosnoski added a comment -

        Oh, and note that the conversion used by default for java.sql.Date does add the appropriate bias for the local time zone, as required by the java.sql.Date specification - so if you want dates converted to your local zone, just use the java.sql.Date type (or wrap these methods with your own serializer/deserializers).

        Show
        Dennis Sosnoski added a comment - Oh, and note that the conversion used by default for java.sql.Date does add the appropriate bias for the local time zone, as required by the java.sql.Date specification - so if you want dates converted to your local zone, just use the java.sql.Date type (or wrap these methods with your own serializer/deserializers).

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Ryan Senior
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: