### Question:
TimePosition implements ITimePosition, Comparable<ITimePosition>, Serializable { @Override public String toISO8601Format() { final StringBuffer isoDate = new StringBuffer(); isoDate.append(Long.toString(getYear())); if (getMonth() != NOT_SET) { isoDate.append("-"); if (getMonth() < 10) { isoDate.append("0"); } isoDate.append(getMonth()); } else { return isoDate.toString(); } if (getDay() != NOT_SET) { isoDate.append("-"); if (getDay() < 10) { isoDate.append("0"); } isoDate.append(getDay()); } else { return isoDate.toString(); } if (getHour() != NOT_SET) { isoDate.append("T"); if (getHour() < 10) { isoDate.append("0"); } isoDate.append(getHour()); } else { return isoDate.toString(); } if (getMinute() != NOT_SET) { isoDate.append(":"); if (getMinute() < 10) { isoDate.append("0"); } isoDate.append(getMinute()); } else { isoDate.toString(); } if (getSecond() != NOT_SET) { isoDate.append(":"); if (getSecond() < 10) { isoDate.append("0"); } String fullSec = Double.toString(second); int end = fullSec.indexOf(".")+4; if(fullSec.endsWith(".0")){ fullSec = fullSec.substring(0, fullSec.length()-2); end -=2; } else if (fullSec.contains(".")){ String start = fullSec.substring(0, fullSec.indexOf(".")); String decimalplaces = String.format("%-3s", fullSec.substring(fullSec.indexOf(".")+1)).replace(' ', '0'); fullSec = new StringBuilder(start).append(".").append(decimalplaces).toString(); } if(end > fullSec.length()){ end = fullSec.length(); } isoDate.append(fullSec.substring(0,end)); } else { return isoDate.toString(); } if (timeZone != null && !timeZone.equals("Z")) { isoDate.append(timeZone); } return isoDate.toString(); } TimePosition(final String timePos); @Override long getYear(); @Override int getMonth(); @Override int getDay(); @Override int getHour(); @Override int getMinute(); @Override float getSecond(); @Deprecated ITimeResolution getTimeResolution(); @Override String toISO8601Format(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(final ITimePosition timePosP); @Override int compare(final ITimePosition o1, final ITimePosition o2); @Override boolean before(final ITimePosition timePosP); @Override boolean after(final ITimePosition timePosP); @Override Calendar getCalendar(); @Override String getTimezone(); void setTimezone(final String timezone); static final String YEAR_PATTERN; static final String MONTH_PATTERN; static final String DAY_PATTERN; static final String HOUR_PATTERN; static final String MINUTE_PATTERN; static final String SECOND_PATTERN; static final String UTC_PATTERN; }### Answer:
@Test public void shouldCreateTimePositionFromStringWithMicros() { TimePosition tp = new TimePosition("2017-08-31T22:04:06.600000+00:00"); Assert.assertThat(tp.toISO8601Format(), Is.is("2017-08-31T22:04:06.600+00:00")); }
@Test public void shouldCreateTimePositionFromStringWithTimeZone() { TimePosition tp = new TimePosition("2017-08-31T22:04:06+11:30"); Assert.assertThat(tp.toISO8601Format(), Is.is("2017-08-31T22:04:06+11:30")); }