@Test public void testGetDateUsingDemarkatedMatch() { DateFormatter formatter = new DateFormatter(); Date result = DateFromString.getDateUsingDemarkatedMatch( "/data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc", "#wrfout_d01_#yyyy-MM-dd_HHmm", '#'); assertThat(result).isNotNull(); assertThat(formatter.toDateTimeStringISO(result)).isEqualTo("2006-07-06T08:00:00Z"); result = DateFromString.getDateUsingDemarkatedMatch("C:\\data\\nomads\\gfs-hi\\gfs_3_20061129_0600", "#gfs_3_#yyyyMMdd_HH", '#'); assertThat(result).isNotNull(); assertThat(formatter.toDateTimeStringISO(result)).isEqualTo("2006-11-29T06:00:00Z"); result = DateFromString.getDateUsingDemarkatedMatch("/data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc", "yyyyMMddHH#/wrfout_d01_#", '#'); assertThat(result).isNotNull(); assertThat(formatter.toDateTimeStringISO(result)).isEqualTo("2006-07-06T11:00:00Z"); }
public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark) { int pos1 = dateFormatString.indexOf(demark); int pos2 = dateFormatString.indexOf(demark, pos1 + 1); if ((pos1 < 0) || (pos2 < 0)) { logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '" + dateFormatString + "'", new Throwable()); return null; } String match = dateFormatString.substring(pos1 + 1, pos2); int pos3 = dateString.indexOf(match); if (pos3 < 0) { return null; } if (pos1 > 0) { dateFormatString = dateFormatString.substring(0, pos1); dateString = dateString.substring(pos3 - dateFormatString.length(), pos3); } else { dateFormatString = dateFormatString.substring(pos2 + 1); dateString = dateString.substring(pos3 + match.length()); } int posDot1 = 0; while (dateFormatString.charAt(posDot1) == '.') posDot1++; int posDot2 = dateFormatString.length(); while (dateFormatString.charAt(posDot2 - 1) == '.') posDot2--; if (posDot1 != 0 || posDot2 != dateFormatString.length()) { dateFormatString = dateFormatString.substring(posDot1, posDot2); dateString = dateString.substring(posDot1, posDot2); } return getDateUsingCompleteDateFormatWithOffset(dateString, dateFormatString, 0); }
DateFromString { public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark) { int pos1 = dateFormatString.indexOf(demark); int pos2 = dateFormatString.indexOf(demark, pos1 + 1); if ((pos1 < 0) || (pos2 < 0)) { logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '" + dateFormatString + "'", new Throwable()); return null; } String match = dateFormatString.substring(pos1 + 1, pos2); int pos3 = dateString.indexOf(match); if (pos3 < 0) { return null; } if (pos1 > 0) { dateFormatString = dateFormatString.substring(0, pos1); dateString = dateString.substring(pos3 - dateFormatString.length(), pos3); } else { dateFormatString = dateFormatString.substring(pos2 + 1); dateString = dateString.substring(pos3 + match.length()); } int posDot1 = 0; while (dateFormatString.charAt(posDot1) == '.') posDot1++; int posDot2 = dateFormatString.length(); while (dateFormatString.charAt(posDot2 - 1) == '.') posDot2--; if (posDot1 != 0 || posDot2 != dateFormatString.length()) { dateFormatString = dateFormatString.substring(posDot1, posDot2); dateString = dateString.substring(posDot1, posDot2); } return getDateUsingCompleteDateFormatWithOffset(dateString, dateFormatString, 0); } }
DateFromString { public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark) { int pos1 = dateFormatString.indexOf(demark); int pos2 = dateFormatString.indexOf(demark, pos1 + 1); if ((pos1 < 0) || (pos2 < 0)) { logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '" + dateFormatString + "'", new Throwable()); return null; } String match = dateFormatString.substring(pos1 + 1, pos2); int pos3 = dateString.indexOf(match); if (pos3 < 0) { return null; } if (pos1 > 0) { dateFormatString = dateFormatString.substring(0, pos1); dateString = dateString.substring(pos3 - dateFormatString.length(), pos3); } else { dateFormatString = dateFormatString.substring(pos2 + 1); dateString = dateString.substring(pos3 + match.length()); } int posDot1 = 0; while (dateFormatString.charAt(posDot1) == '.') posDot1++; int posDot2 = dateFormatString.length(); while (dateFormatString.charAt(posDot2 - 1) == '.') posDot2--; if (posDot1 != 0 || posDot2 != dateFormatString.length()) { dateFormatString = dateFormatString.substring(posDot1, posDot2); dateString = dateString.substring(posDot1, posDot2); } return getDateUsingCompleteDateFormatWithOffset(dateString, dateFormatString, 0); }  }
DateFromString { public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark) { int pos1 = dateFormatString.indexOf(demark); int pos2 = dateFormatString.indexOf(demark, pos1 + 1); if ((pos1 < 0) || (pos2 < 0)) { logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '" + dateFormatString + "'", new Throwable()); return null; } String match = dateFormatString.substring(pos1 + 1, pos2); int pos3 = dateString.indexOf(match); if (pos3 < 0) { return null; } if (pos1 > 0) { dateFormatString = dateFormatString.substring(0, pos1); dateString = dateString.substring(pos3 - dateFormatString.length(), pos3); } else { dateFormatString = dateFormatString.substring(pos2 + 1); dateString = dateString.substring(pos3 + match.length()); } int posDot1 = 0; while (dateFormatString.charAt(posDot1) == '.') posDot1++; int posDot2 = dateFormatString.length(); while (dateFormatString.charAt(posDot2 - 1) == '.') posDot2--; if (posDot1 != 0 || posDot2 != dateFormatString.length()) { dateFormatString = dateFormatString.substring(posDot1, posDot2); dateString = dateString.substring(posDot1, posDot2); } return getDateUsingCompleteDateFormatWithOffset(dateString, dateFormatString, 0); }  static Date getDateUsingSimpleDateFormat(String dateString, String dateFormatString); static Date getDateUsingDemarkatedCount(String dateString, String dateFormatString, char demark); static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark); static Date getDateUsingCompleteDateFormat(String dateString, String dateFormatString); static Date getDateUsingCompleteDateFormatWithOffset(String dateString, String dateFormatString,
      int startIndex); static Date getDateUsingRegExp(String dateString, String matchPattern, String substitutionPattern); static Date getDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern,
      String dateFormatString); }
DateFromString { public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark) { int pos1 = dateFormatString.indexOf(demark); int pos2 = dateFormatString.indexOf(demark, pos1 + 1); if ((pos1 < 0) || (pos2 < 0)) { logger.error("Must delineate Date between 2 '#' chars, dateFormatString = '" + dateFormatString + "'", new Throwable()); return null; } String match = dateFormatString.substring(pos1 + 1, pos2); int pos3 = dateString.indexOf(match); if (pos3 < 0) { return null; } if (pos1 > 0) { dateFormatString = dateFormatString.substring(0, pos1); dateString = dateString.substring(pos3 - dateFormatString.length(), pos3); } else { dateFormatString = dateFormatString.substring(pos2 + 1); dateString = dateString.substring(pos3 + match.length()); } int posDot1 = 0; while (dateFormatString.charAt(posDot1) == '.') posDot1++; int posDot2 = dateFormatString.length(); while (dateFormatString.charAt(posDot2 - 1) == '.') posDot2--; if (posDot1 != 0 || posDot2 != dateFormatString.length()) { dateFormatString = dateFormatString.substring(posDot1, posDot2); dateString = dateString.substring(posDot1, posDot2); } return getDateUsingCompleteDateFormatWithOffset(dateString, dateFormatString, 0); }  static Date getDateUsingSimpleDateFormat(String dateString, String dateFormatString); static Date getDateUsingDemarkatedCount(String dateString, String dateFormatString, char demark); static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark); static Date getDateUsingCompleteDateFormat(String dateString, String dateFormatString); static Date getDateUsingCompleteDateFormatWithOffset(String dateString, String dateFormatString,
      int startIndex); static Date getDateUsingRegExp(String dateString, String matchPattern, String substitutionPattern); static Date getDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern,
      String dateFormatString);  }