[
https://issues.apache.org/jira/browse/WICKET-3510?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13010052#comment-13010052
]
Andera Del Bene commented on WICKET-3510:
-----------------------------------------
Hi Bertrand,
are you sure that Changeset 1079694 introduced this bug? I think that it was
present since Changeset 1077866, related to issue 3501. Anyway after some
googling I've found an insightful post by Vinod Singh here:
http://blog.vinodsingh.com/2009/03/date-and-timezone-in-java.html.
So I've used his function 'Date changeTimeZone(Date date, TimeZone zone)' to
fix this issue. But I'm not sure where to put this function. For now I've
inserted it directly into class DateTimeField.java but I'm afraid it's not the
right place. Is there in Wicket a better place ( maybe an utility class) to put
this function in?
Any suggestion?
PS: I've attached the fix including testsWithDateModels.patch
> DateTimeField improperly converts time causing wrong dates when the server's
> current date is different from the client's date.
> ------------------------------------------------------------------------------------------------------------------------------
>
> Key: WICKET-3510
> URL: https://issues.apache.org/jira/browse/WICKET-3510
> Project: Wicket
> Issue Type: Bug
> Components: wicket-datetime
> Affects Versions: 1.5-RC2
> Reporter: Bertrand Guay-Paquet
> Labels: datepicker, datetime
> Fix For: 1.5-RC3
>
> Attachments: DateConverterFix.patch, FailingTest.patch,
> TestDateConverter.java, dateModelConversionFix.patch,
> doubleConversionFix.patch, testsWithDateModels.patch
>
>
> 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.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira