@Test public void shouldFailToParseIfNotStartingWithP() { final String text = "T01S"; assertThatThrownBy(() -> Interval.parse(text)).isInstanceOf(DateTimeParseException.class); }
public static Interval parse(final String text) { String sign = ""; int startOffset = 0; if (text.startsWith("-")) { startOffset = 1; sign = "-"; } else if (text.startsWith("+")) { startOffset = 1; } final int durationOffset = text.indexOf('T'); if (durationOffset == -1) { return new Interval(Period.parse(text), Duration.ZERO); } else if (durationOffset == startOffset + 1) { return new Interval(Period.ZERO, Duration.parse(text)); } return new Interval( Period.parse(text.substring(0, durationOffset)), Duration.parse(sign + "P" + text.substring(durationOffset))); }
Interval implements TemporalAmount { public static Interval parse(final String text) { String sign = ""; int startOffset = 0; if (text.startsWith("-")) { startOffset = 1; sign = "-"; } else if (text.startsWith("+")) { startOffset = 1; } final int durationOffset = text.indexOf('T'); if (durationOffset == -1) { return new Interval(Period.parse(text), Duration.ZERO); } else if (durationOffset == startOffset + 1) { return new Interval(Period.ZERO, Duration.parse(text)); } return new Interval( Period.parse(text.substring(0, durationOffset)), Duration.parse(sign + "P" + text.substring(durationOffset))); } }
Interval implements TemporalAmount { public static Interval parse(final String text) { String sign = ""; int startOffset = 0; if (text.startsWith("-")) { startOffset = 1; sign = "-"; } else if (text.startsWith("+")) { startOffset = 1; } final int durationOffset = text.indexOf('T'); if (durationOffset == -1) { return new Interval(Period.parse(text), Duration.ZERO); } else if (durationOffset == startOffset + 1) { return new Interval(Period.ZERO, Duration.parse(text)); } return new Interval( Period.parse(text.substring(0, durationOffset)), Duration.parse(sign + "P" + text.substring(durationOffset))); } Interval(final Period period, final Duration duration);  Interval(final Duration duration);  Interval(final Period period); }
Interval implements TemporalAmount { public static Interval parse(final String text) { String sign = ""; int startOffset = 0; if (text.startsWith("-")) { startOffset = 1; sign = "-"; } else if (text.startsWith("+")) { startOffset = 1; } final int durationOffset = text.indexOf('T'); if (durationOffset == -1) { return new Interval(Period.parse(text), Duration.ZERO); } else if (durationOffset == startOffset + 1) { return new Interval(Period.ZERO, Duration.parse(text)); } return new Interval( Period.parse(text.substring(0, durationOffset)), Duration.parse(sign + "P" + text.substring(durationOffset))); } Interval(final Period period, final Duration duration);  Interval(final Duration duration);  Interval(final Period period); Period getPeriod(); Duration getDuration(); long toEpochMilli(final long fromEpochMilli); @Override long get(final TemporalUnit unit); @Override List<TemporalUnit> getUnits(); @Override Temporal addTo(final Temporal temporal); @Override Temporal subtractFrom(final Temporal temporal); @Override int hashCode(); @Override boolean equals(final Object o); @Override String toString(); static Interval parse(final String text); }
Interval implements TemporalAmount { public static Interval parse(final String text) { String sign = ""; int startOffset = 0; if (text.startsWith("-")) { startOffset = 1; sign = "-"; } else if (text.startsWith("+")) { startOffset = 1; } final int durationOffset = text.indexOf('T'); if (durationOffset == -1) { return new Interval(Period.parse(text), Duration.ZERO); } else if (durationOffset == startOffset + 1) { return new Interval(Period.ZERO, Duration.parse(text)); } return new Interval( Period.parse(text.substring(0, durationOffset)), Duration.parse(sign + "P" + text.substring(durationOffset))); } Interval(final Period period, final Duration duration);  Interval(final Duration duration);  Interval(final Period period); Period getPeriod(); Duration getDuration(); long toEpochMilli(final long fromEpochMilli); @Override long get(final TemporalUnit unit); @Override List<TemporalUnit> getUnits(); @Override Temporal addTo(final Temporal temporal); @Override Temporal subtractFrom(final Temporal temporal); @Override int hashCode(); @Override boolean equals(final Object o); @Override String toString(); static Interval parse(final String text);  }