private static final Date toDate(String str, Date time) {
    if (str == null) return time;

    Calendar tc = Calendar.getInstance();
    if (time == null) {
      tc.set(Calendar.HOUR_OF_DAY, 0);
      tc.set(Calendar.MINUTE, 0);
      tc.set(Calendar.SECOND, 0);
      tc.set(Calendar.MILLISECOND, 0);
    } else {
      tc.setTime(time);
    }

    str = str.toUpperCase().trim();

    boolean success = false;
    for (int i = 0; i < DATE_FORMATS.length; i++) {
      try {
        Calendar c = Calendar.getInstance();
        KSDateTimeFormatter df = DATE_FORMATS[i];
        c.setTime(df.parse(str));
        tc.set(Calendar.YEAR, c.get(Calendar.YEAR));
        tc.set(Calendar.MONTH, c.get(Calendar.MONTH));
        tc.set(Calendar.DATE, c.get(Calendar.DATE));
        success = true;
        break;
      } catch (IllegalArgumentException e) {
      }
    }

    return success ? tc.getTime() : time;
  }
  // TODO: KSAP-743 convert these to property editors, add to standard registry
  private static final Date toTime(String str, Date date) {
    if (str == null) return date;

    Calendar dc = Calendar.getInstance();
    if (date == null) {
      dc.set(Calendar.YEAR, 1970);
      dc.set(Calendar.MONTH, Calendar.JANUARY);
      dc.set(Calendar.DATE, 1);
    } else {
      dc.setTime(date);
    }
    dc.set(Calendar.HOUR_OF_DAY, 0);
    dc.set(Calendar.MINUTE, 0);
    dc.set(Calendar.SECOND, 0);
    dc.set(Calendar.MILLISECOND, 0);

    str = str.toUpperCase().trim();
    if (str.endsWith("A") || str.endsWith("P")) str += "M";

    boolean success = false;
    for (int i = 0; i < TIME_FORMATS.length; i++) {
      try {
        Calendar c = Calendar.getInstance();
        KSDateTimeFormatter df = TIME_FORMATS[i];
        c.setTime(df.parse(str));
        if (i == TIME_FORMATS.length - 1)
          if (c.get(Calendar.HOUR_OF_DAY) < 8) c.set(Calendar.AM_PM, Calendar.PM);
        dc.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY));
        dc.set(Calendar.MINUTE, c.get(Calendar.MINUTE));
        success = true;
        break;
      } catch (IllegalArgumentException e) {
      }
    }

    return success ? dc.getTime() : date;
  }