@Test public void testCompleteDate_onlyYear_shouldWork() throws Exception { assertThat(Utilities.completeDate("2015-"), is("2015-12-31")); }
public static String completeDate(String date) { if (date.endsWith("-")) { date = date.substring(0, date.length()-1); } String val = ""; if (date.length() < 4) { return val; } else if (date.length() == 4) { val = date + "-12-31"; } else if ((date.length() == 7) || (date.length() == 6)) { int ind = date.indexOf("-"); String monthStr = date.substring(ind + 1, date.length()); if (monthStr.length() == 1) { monthStr = "0" + monthStr; } if (monthStr.equals("02")) { val = date.substring(0, 4) + "-" + monthStr + "-28"; } else if ((monthStr.equals("04")) || (monthStr.equals("06")) || (monthStr.equals("09")) || (monthStr.equals("11"))) { val = date.substring(0, 4) + "-" + monthStr + "-30"; } else { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { monthStr = "12"; } val = date.substring(0, 4) + "-" + monthStr + "-31"; } } else { int ind = date.indexOf("-"); int ind2 = date.lastIndexOf("-"); String monthStr = date.substring(ind + 1, ind + 3); try { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { val = date.substring(0, 4) + "-12" + date.substring(ind + 3, date.length()); } String dayStr = date.substring(ind2 + 1, ind2 + 3); int day = Integer.parseInt(dayStr); if (day > 31 || day < 1) { val = date.substring(0, 8) + "28"; } } catch (Exception e) { } val = date.trim(); } val = val.replace(" ", "T"); if (!val.matches("\\d{4}-\\d{2}-\\d{2}") || (Integer.parseInt(val.substring(0, 4)) < minYear || todayYear < Integer.parseInt(val.substring(0, 4)))) { val = ""; } return val; }
Utilities { public static String completeDate(String date) { if (date.endsWith("-")) { date = date.substring(0, date.length()-1); } String val = ""; if (date.length() < 4) { return val; } else if (date.length() == 4) { val = date + "-12-31"; } else if ((date.length() == 7) || (date.length() == 6)) { int ind = date.indexOf("-"); String monthStr = date.substring(ind + 1, date.length()); if (monthStr.length() == 1) { monthStr = "0" + monthStr; } if (monthStr.equals("02")) { val = date.substring(0, 4) + "-" + monthStr + "-28"; } else if ((monthStr.equals("04")) || (monthStr.equals("06")) || (monthStr.equals("09")) || (monthStr.equals("11"))) { val = date.substring(0, 4) + "-" + monthStr + "-30"; } else { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { monthStr = "12"; } val = date.substring(0, 4) + "-" + monthStr + "-31"; } } else { int ind = date.indexOf("-"); int ind2 = date.lastIndexOf("-"); String monthStr = date.substring(ind + 1, ind + 3); try { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { val = date.substring(0, 4) + "-12" + date.substring(ind + 3, date.length()); } String dayStr = date.substring(ind2 + 1, ind2 + 3); int day = Integer.parseInt(dayStr); if (day > 31 || day < 1) { val = date.substring(0, 8) + "28"; } } catch (Exception e) { } val = date.trim(); } val = val.replace(" ", "T"); if (!val.matches("\\d{4}-\\d{2}-\\d{2}") || (Integer.parseInt(val.substring(0, 4)) < minYear || todayYear < Integer.parseInt(val.substring(0, 4)))) { val = ""; } return val; } }
Utilities { public static String completeDate(String date) { if (date.endsWith("-")) { date = date.substring(0, date.length()-1); } String val = ""; if (date.length() < 4) { return val; } else if (date.length() == 4) { val = date + "-12-31"; } else if ((date.length() == 7) || (date.length() == 6)) { int ind = date.indexOf("-"); String monthStr = date.substring(ind + 1, date.length()); if (monthStr.length() == 1) { monthStr = "0" + monthStr; } if (monthStr.equals("02")) { val = date.substring(0, 4) + "-" + monthStr + "-28"; } else if ((monthStr.equals("04")) || (monthStr.equals("06")) || (monthStr.equals("09")) || (monthStr.equals("11"))) { val = date.substring(0, 4) + "-" + monthStr + "-30"; } else { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { monthStr = "12"; } val = date.substring(0, 4) + "-" + monthStr + "-31"; } } else { int ind = date.indexOf("-"); int ind2 = date.lastIndexOf("-"); String monthStr = date.substring(ind + 1, ind + 3); try { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { val = date.substring(0, 4) + "-12" + date.substring(ind + 3, date.length()); } String dayStr = date.substring(ind2 + 1, ind2 + 3); int day = Integer.parseInt(dayStr); if (day > 31 || day < 1) { val = date.substring(0, 8) + "28"; } } catch (Exception e) { } val = date.trim(); } val = val.replace(" ", "T"); if (!val.matches("\\d{4}-\\d{2}-\\d{2}") || (Integer.parseInt(val.substring(0, 4)) < minYear || todayYear < Integer.parseInt(val.substring(0, 4)))) { val = ""; } return val; }  }
Utilities { public static String completeDate(String date) { if (date.endsWith("-")) { date = date.substring(0, date.length()-1); } String val = ""; if (date.length() < 4) { return val; } else if (date.length() == 4) { val = date + "-12-31"; } else if ((date.length() == 7) || (date.length() == 6)) { int ind = date.indexOf("-"); String monthStr = date.substring(ind + 1, date.length()); if (monthStr.length() == 1) { monthStr = "0" + monthStr; } if (monthStr.equals("02")) { val = date.substring(0, 4) + "-" + monthStr + "-28"; } else if ((monthStr.equals("04")) || (monthStr.equals("06")) || (monthStr.equals("09")) || (monthStr.equals("11"))) { val = date.substring(0, 4) + "-" + monthStr + "-30"; } else { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { monthStr = "12"; } val = date.substring(0, 4) + "-" + monthStr + "-31"; } } else { int ind = date.indexOf("-"); int ind2 = date.lastIndexOf("-"); String monthStr = date.substring(ind + 1, ind + 3); try { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { val = date.substring(0, 4) + "-12" + date.substring(ind + 3, date.length()); } String dayStr = date.substring(ind2 + 1, ind2 + 3); int day = Integer.parseInt(dayStr); if (day > 31 || day < 1) { val = date.substring(0, 8) + "28"; } } catch (Exception e) { } val = date.trim(); } val = val.replace(" ", "T"); if (!val.matches("\\d{4}-\\d{2}-\\d{2}") || (Integer.parseInt(val.substring(0, 4)) < minYear || todayYear < Integer.parseInt(val.substring(0, 4)))) { val = ""; } return val; }  static void setTmpPath(String tmp_path); static String getTmpPath(); static void updateDates(String fromDate, String untilDate); static boolean isValidDate(String dateString); static String completeDate(String date); static String toString(Document doc); static String innerXmlToString(Node node); static Element findNode(String attribut, String value, NodeList orgs); static void generateIDs(Document doc); static void trimEOL(Node node, Document doc); static void clearTmpDirectory(); static String storeTmpFile(InputStream inBinary); static String storeToTmpXmlFile(InputStream inBinary); static void getBinaryURLContent(File file, InputStream in); static String formatDate(Date date); static Date parseStringDate(String dateString); static String getHalIDFromHalDocID(String halDocID); static String getVersionFromURI(String uri); static String getHalURIFromFilename(String filename); static Set<String> getDates(); static String trimEncodedCharaters(String string); static void unzipIt(String file, String outPath); static String readFile(String fileName); static InputStream request(String request); static String formatXMLString(String xmlString); static void checkPath(String path); static String convertStreamToString(InputStream is); final static String removeAccents(String input); final static Element getElementByAttribute(String attr, String value, Element root); static Element matchAuthor(String fullname, NodeList authorsFromfulltextTeiHeader); }
Utilities { public static String completeDate(String date) { if (date.endsWith("-")) { date = date.substring(0, date.length()-1); } String val = ""; if (date.length() < 4) { return val; } else if (date.length() == 4) { val = date + "-12-31"; } else if ((date.length() == 7) || (date.length() == 6)) { int ind = date.indexOf("-"); String monthStr = date.substring(ind + 1, date.length()); if (monthStr.length() == 1) { monthStr = "0" + monthStr; } if (monthStr.equals("02")) { val = date.substring(0, 4) + "-" + monthStr + "-28"; } else if ((monthStr.equals("04")) || (monthStr.equals("06")) || (monthStr.equals("09")) || (monthStr.equals("11"))) { val = date.substring(0, 4) + "-" + monthStr + "-30"; } else { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { monthStr = "12"; } val = date.substring(0, 4) + "-" + monthStr + "-31"; } } else { int ind = date.indexOf("-"); int ind2 = date.lastIndexOf("-"); String monthStr = date.substring(ind + 1, ind + 3); try { int month = Integer.parseInt(monthStr); if (month > 12 || month < 1) { val = date.substring(0, 4) + "-12" + date.substring(ind + 3, date.length()); } String dayStr = date.substring(ind2 + 1, ind2 + 3); int day = Integer.parseInt(dayStr); if (day > 31 || day < 1) { val = date.substring(0, 8) + "28"; } } catch (Exception e) { } val = date.trim(); } val = val.replace(" ", "T"); if (!val.matches("\\d{4}-\\d{2}-\\d{2}") || (Integer.parseInt(val.substring(0, 4)) < minYear || todayYear < Integer.parseInt(val.substring(0, 4)))) { val = ""; } return val; }  static void setTmpPath(String tmp_path); static String getTmpPath(); static void updateDates(String fromDate, String untilDate); static boolean isValidDate(String dateString); static String completeDate(String date); static String toString(Document doc); static String innerXmlToString(Node node); static Element findNode(String attribut, String value, NodeList orgs); static void generateIDs(Document doc); static void trimEOL(Node node, Document doc); static void clearTmpDirectory(); static String storeTmpFile(InputStream inBinary); static String storeToTmpXmlFile(InputStream inBinary); static void getBinaryURLContent(File file, InputStream in); static String formatDate(Date date); static Date parseStringDate(String dateString); static String getHalIDFromHalDocID(String halDocID); static String getVersionFromURI(String uri); static String getHalURIFromFilename(String filename); static Set<String> getDates(); static String trimEncodedCharaters(String string); static void unzipIt(String file, String outPath); static String readFile(String fileName); static InputStream request(String request); static String formatXMLString(String xmlString); static void checkPath(String path); static String convertStreamToString(InputStream is); final static String removeAccents(String input); final static Element getElementByAttribute(String attr, String value, Element root); static Element matchAuthor(String fullname, NodeList authorsFromfulltextTeiHeader);  }