6363public class ParamProcessWorker implements DispatchWorker {
6464
6565 private static final Logger s_logger = Logger .getLogger (ParamProcessWorker .class .getName ());
66- public final DateFormat inputFormat = new SimpleDateFormat ("yyyy-MM-dd" );
67- public final DateFormat newInputFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
66+ private static final String inputFormatString = "yyyy-MM-dd" ;
67+ private static final String newInputFormatString = "yyyy-MM-dd HH:mm:ss" ;
68+ public static final DateFormat inputFormat = new SimpleDateFormat (inputFormatString );
69+ public static final DateFormat newInputFormat = new SimpleDateFormat (newInputFormatString );
6870
6971 @ Inject
7072 protected AccountManager _accountMgr ;
@@ -333,26 +335,7 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
333335 field .set (cmdObj , Boolean .valueOf (paramObj .toString ()));
334336 break ;
335337 case DATE :
336- // This piece of code is for maintaining backward compatibility
337- // and support both the date formats(Bug 9724)
338- final boolean isObjInNewDateFormat = isObjInNewDateFormat (paramObj .toString ());
339- if (isObjInNewDateFormat ) {
340- final DateFormat newFormat = newInputFormat ;
341- synchronized (newFormat ) {
342- field .set (cmdObj , newFormat .parse (paramObj .toString ()));
343- }
344- } else {
345- final DateFormat format = inputFormat ;
346- synchronized (format ) {
347- Date date = format .parse (paramObj .toString ());
348- if (field .getName ().equals ("startDate" )) {
349- date = messageDate (date , 0 , 0 , 0 );
350- } else if (field .getName ().equals ("endDate" )) {
351- date = messageDate (date , 23 , 59 , 59 );
352- }
353- field .set (cmdObj , date );
354- }
355- }
338+ parseAndSetDate (field , cmdObj , paramObj );
356339 break ;
357340 case FLOAT :
358341 // Assuming that the parameters have been checked for required before now,
@@ -428,9 +411,6 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
428411 }
429412 }
430413 break ;
431- case TZDATE :
432- field .set (cmdObj , DateUtil .parseTZDateString (paramObj .toString ()));
433- break ;
434414 case MAP :
435415 default :
436416 field .set (cmdObj , paramObj );
@@ -442,6 +422,33 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
442422 " is not accessible]" );
443423 }
444424 }
425+ private void parseAndSetDate (Field field , BaseCmd cmdObj , Object paramObj ) throws IllegalAccessException , ParseException {
426+ try {
427+ field .set (cmdObj , DateUtil .parseTZDateString (paramObj .toString ()));
428+ return ;
429+ } catch (ParseException parseException ) {
430+ s_logger .debug (String .format ("Could not parse date [%s] with timezone parser, trying to parse without timezone." , paramObj ));
431+ }
432+ if (isObjInNewDateFormat (paramObj .toString ())) {
433+ s_logger .debug (String .format ("Parsing date [%s] using the [%s] format." , paramObj , newInputFormatString ));
434+ final DateFormat newFormat = newInputFormat ;
435+ synchronized (newFormat ) {
436+ field .set (cmdObj , newFormat .parse (paramObj .toString ()));
437+ }
438+ } else {
439+ s_logger .debug (String .format ("Parsing date [%s] using the [%s] format." , paramObj , inputFormatString ));
440+ final DateFormat format = inputFormat ;
441+ synchronized (format ) {
442+ Date date = format .parse (paramObj .toString ());
443+ if (field .getName ().equals ("startDate" )) {
444+ date = messageDate (date , 0 , 0 , 0 );
445+ } else if (field .getName ().equals ("endDate" )) {
446+ date = messageDate (date , 23 , 59 , 59 );
447+ }
448+ field .set (cmdObj , date );
449+ }
450+ }
451+ }
445452
446453 private boolean isObjInNewDateFormat (final String string ) {
447454 final Matcher matcher = BaseCmd .newInputDateFormat .matcher (string );
0 commit comments