Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-3510

DateTimeField improperly converts time causing wrong dates when the server's current date is different from the client's date.

    XMLWordPrintableJSON

    Details

      Description

      The bug is in DateTimeField#convertInput().
      <code>
      // Get year, month and day ignoring any timezone of the Date object
      Calendar cal = Calendar.getInstance();
      cal.setTime(dateFieldInput);
      int year = cal.get(Calendar.YEAR);
      int month = cal.get(Calendar.MONTH) + 1;
      int day = cal.get(Calendar.DAY_OF_MONTH);
      int hours = (hoursInput == null ? 0 : hoursInput % 24);
      int minutes = (minutesInput == null ? 0 : minutesInput);

      // Use the input to create a date object with proper timezone
      MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0,
      DateTimeZone.forTimeZone(getClientTimeZone()));
      </code>
      If the server's current date is different from the client's, this produces wrong output. I attached a patch with a test case that simulates this condition.

      I don't know why this "casting" of day, month, year is done.

        Attachments

        1. DateConverterFix.patch
          4 kB
          Andrea Del Bene
        2. dateModelConversionFix_TimeField_NoEnclosure.patch
          17 kB
          Bertrand Guay-Paquet
        3. dateModelConversionFix_TimeField.patch
          16 kB
          Bertrand Guay-Paquet
        4. dateModelConversionFix.patch
          11 kB
          Andrea Del Bene
        5. doubleConversionFix.patch
          4 kB
          Andrea Del Bene
        6. FailingTest.patch
          2 kB
          Bertrand Guay-Paquet
        7. TestDateConverter.java
          1 kB
          Bertrand Guay-Paquet
        8. testsWithDateModels.patch
          9 kB
          Bertrand Guay-Paquet

          Activity

            People

            • Assignee:
              ivaynberg Igor Vaynberg
              Reporter:
              berniegp Bertrand Guay-Paquet
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: