/** * Return an integer value to indicate the level of completeness of * a String value that represents a valid point of time. * -1 means invalid string value; * 1 means only HH component is present; 2 means HHmm; * 3 for HHmmss, 4 for HHmmss.SSS * These result is regardless of the format of the time string * (whether or not it is in extended format) */ public static int analyseTimeString(String value) { if(value == null || value.equals("")) { return -1; } String timeComp = value; int zonePst = tZonePresent(value); if(zonePst > 0) { timeComp = value.substring(0, zonePst); } timeComp = timeComp.replace(":", ""); return timeComp.length()/2 > 4? 4 : timeComp.length()/2; }
/** * Return an integer value to indicate the level of completeness of * a String value that represents a valid point of time. * -1 means invalid string value; * 1 means only HH component is present; 2 means HHmm; * 3 for HHmmss, 4 for HHmmss.SSS * These result is regardless of the format of the time string * (whether or not it is in extended format) */ public static int analyseTimeString(String value) { if(value == null || value.equals("")) { return -1; } String timeComp = value; int zonePst = tZonePresent(value); if(zonePst > 0) { timeComp = value.substring(0, zonePst); } timeComp = timeComp.replace(":", ""); return timeComp.length()/2 > 4? 4 : timeComp.length()/2; }
int zonePst = tZonePresent(value);
public static String basicToExtendedTime(String time) { if(time.indexOf(":") > 0 || time.length() <= 2) { return time; } int zonePst = tZonePresent(time); StringBuffer timeAsBuffer = null; StringBuffer zoneAsBuffer = null; if(zonePst > 0) { timeAsBuffer = new StringBuffer(time.substring(0, zonePst)); zoneAsBuffer = new StringBuffer(time.substring(zonePst)); } else { timeAsBuffer = new StringBuffer(time); zoneAsBuffer = new StringBuffer(""); } int timeElemSize = analyseTimeString(time) > 3 ? 3 : analyseTimeString(time); //insert ':' for time elements for(int i = 0; i < timeElemSize -1; i++) { timeAsBuffer.insert(2*(i+1) + i, ":"); } //now dealing with zone if(zoneAsBuffer.length() > 3) { zoneAsBuffer.insert(3, ":"); } return timeAsBuffer.append(zoneAsBuffer).toString(); }
int zonePst = tZonePresent(value);
public static String basicToExtendedTime(String time) { if(time.indexOf(":") > 0 || time.length() <= 2) { return time; } int zonePst = tZonePresent(time); StringBuffer timeAsBuffer = null; StringBuffer zoneAsBuffer = null; if(zonePst > 0) { timeAsBuffer = new StringBuffer(time.substring(0, zonePst)); zoneAsBuffer = new StringBuffer(time.substring(zonePst)); } else { timeAsBuffer = new StringBuffer(time); zoneAsBuffer = new StringBuffer(""); } int timeElemSize = analyseTimeString(time) > 3 ? 3 : analyseTimeString(time); //insert ':' for time elements for(int i = 0; i < timeElemSize -1; i++) { timeAsBuffer.insert(2*(i+1) + i, ":"); } //now dealing with zone if(zoneAsBuffer.length() > 3) { zoneAsBuffer.insert(3, ":"); } return timeAsBuffer.append(zoneAsBuffer).toString(); }
} else { boolean isExtended = pattern.indexOf(":") > 0; boolean zoneExist = tZonePresent(pattern) > 0; int formatInt = analyseTimeString(pattern); switch (formatInt) {
} else { boolean isExtended = pattern.indexOf(":") > 0; boolean zoneExist = tZonePresent(pattern) > 0; int formatInt = analyseTimeString(pattern); switch (formatInt) {
case 4: pattern = "yyyyMMdd'T'HHmmss,SSSSSSSSS"; break; if(tZonePresent(value) > 0) { pattern = pattern + "Z";
case 4: pattern = "yyyyMMdd'T'HHmmss,SSSSSSSSS"; break; if(tZonePresent(value) > 0) { pattern = pattern + "Z";
int zonePosition = tZonePresent(value); if(zonePosition > 0) { String timeElem = value.substring(0, zonePosition);
int zonePosition = tZonePresent(value); if(zonePosition > 0) { String timeElem = value.substring(0, zonePosition);