The "format.parseDateTime" can do some tricky stuff, it seems:

"Parses a datetime from the given text, returning a new DateTime.

The parse will use the zone and chronology specified on this formatter.

If the text contains a time zone string then that will be taken into account in adjusting the time of day as follows. If the ||withOffsetParsed() <http://grepcode.com/file/repo1.maven.org$mav...@joda-time$joda-time@1...@org$joda$time$format$datetimeformatter.java#datetimeformatter.withoffsetparsed%28%29>|| has been called, then the resulting DateTime will have a fixed offset based on the parsed time zone. Otherwise the resulting DateTime will have the zone of this formatter, but the parsed zone may have caused the time to be adjusted."

Can you debug step into that and see if anything funky happens there?

/Stefan



On 2009-07-07 22:47, jpalmer1026 wrote:
I did a little bit of digging and it appears that the problem is in the
convertToObject() in the org.apache.wicket.datetime.DateConverter class.
Specifically, the return date.ToDate() line in the following code:

if (applyTimeZoneDifference)
                {
                        TimeZone zone = getClientTimeZone();
                        ...
}
else
                {
                        try
                        {
                                DateTime date = format.parseDateTime(value);
                                return date.toDate();
                        }
}


jpalmer1026 wrote:
I was thinking the same thing but, as you pointed out, I explicitly set it
to false, so I'm not sure why it's behaving this way. I tried setting it
to true just as an experiment but the results were the same. Has anyone
else seen this?


Stefan Malmesjö wrote:
Could this have anything to do with applyTimeZoneDifference in
PatterDateConverter? It looks like you set it to false, so it shouldn't,
but still... it fits the description pretty well...
/Stefan

On 2009-07-07 19:44, [email protected] wrote:
I am having issues with a custom component that I created. The
component's function is to ensure that the date entered adheres to the
format "^(\\d{2})/(\\d{2})/(\\d{4})$" The problem, though, is when the
form that contains the component is submitted, the date is converted
to the previous day's date. For example, if a date of 07/07/2009 is
entered, the value that gets submitted is 07/06/2009 at 19:00 CDT. My
code (2 classes) is as follows:

public class CustomDateTextField extends TextField {

     public CustomDateTextField(String id, IModel model, Class type) {
         super(id, model, type);
         add(new EzdecDatePicker());
     }

     public CustomDateTextField(String id, IModel model) {
         super(id, model);
         add(new EzdecDatePicker());
     }

     public CustomDateTextField(String id, Class type) {
         super(id, type);
         add(new EzdecDatePicker());
     }

     public CustomDateTextField(String id) {
         super(id);
         add(new EzdecDatePicker());
     }

     @Override
     public IConverter getConverter(Class<?>  type) {
         return new StrictPatternDateConverter();
     }
}

public class StrictPatternDateConverter extends PatternDateConverter {

     public static final String REGEX_PATTERN =
             "^(\\d{2})/(\\d{2})/(\\d{4})$";

     public StrictPatternDateConverter() {
         super("MM/dd/yyyy", false);
     }

     @Override
     public Date convertToObject(String value, Locale locale) {
         final Pattern pattern = Pattern.compile(REGEX_PATTERN);
         if (StringUtils.isNotBlank(value)&&
!pattern.matcher(value).matches()) {
             throw new ConversionException("Invalid date format");
         }
         return super.convertToObject(value, locale);
     }
}



Reply via email to