diff --git a/src/main/java/com/ethlo/time/internal/ErrorUtil.java b/src/main/java/com/ethlo/time/internal/ErrorUtil.java index ae41011..74cf5a9 100644 --- a/src/main/java/com/ethlo/time/internal/ErrorUtil.java +++ b/src/main/java/com/ethlo/time/internal/ErrorUtil.java @@ -35,4 +35,9 @@ public static void raiseUnexpectedEndOfText(final String chars, final int offset { throw new DateTimeParseException("Unexpected end of input: " + chars, chars, offset); } + + public static void raiseMissingTimeZone(String chars, int index) + { + throw new DateTimeParseException("No timezone information: " + chars, chars, index); + } } diff --git a/src/main/java/com/ethlo/time/internal/EthloITU.java b/src/main/java/com/ethlo/time/internal/EthloITU.java index 66ca75f..3423968 100644 --- a/src/main/java/com/ethlo/time/internal/EthloITU.java +++ b/src/main/java/com/ethlo/time/internal/EthloITU.java @@ -20,6 +20,8 @@ * #L% */ +import static com.ethlo.time.internal.ErrorUtil.raiseMissingTimeZone; +import static com.ethlo.time.internal.ErrorUtil.raiseUnexpectedCharacter; import static com.ethlo.time.internal.ErrorUtil.raiseUnexpectedEndOfText; import static com.ethlo.time.internal.LeapSecondHandler.LEAP_SECOND_SECONDS; import static com.ethlo.time.internal.LimitedCharArrayIntegerUtil.DIGIT_9; @@ -180,7 +182,7 @@ private static TimezoneOffset parseTimezone(String chars, int offset) { if (offset >= chars.length()) { - throw new DateTimeParseException("No timezone information: " + chars, chars, offset); + raiseMissingTimeZone(chars, offset); } final int len = chars.length(); final int left = len - offset; @@ -194,7 +196,7 @@ private static TimezoneOffset parseTimezone(String chars, int offset) final char sign = chars.charAt(offset); if (sign != PLUS && sign != MINUS) { - throw new DateTimeParseException("Invalid character starting at position " + offset + ": " + chars, chars, offset); + raiseUnexpectedCharacter(chars, offset); } if (left != 6) @@ -310,7 +312,7 @@ private static Object handleTime(int year, int month, int day, int hour, int min { return new DateTime(Field.SECOND, year, month, day, hour, minute, seconds, 0, null, 0); } - throw new DateTimeParseException("No timezone information: " + chars, chars, 19); + ErrorUtil.raiseMissingTimeZone(chars, 19); } else if (remaining == 0) { @@ -318,7 +320,7 @@ else if (remaining == 0) { return new DateTime(Field.SECOND, year, month, day, hour, minute, 0, 0, null, 0); } - throw new DateTimeParseException("No timezone information: " + chars, chars, 16); + raiseMissingTimeZone(chars, 16); } TimezoneOffset offset = null; diff --git a/src/test/resources/test-data.json b/src/test/resources/test-data.json index 07431e4..715aa08 100644 --- a/src/test/resources/test-data.json +++ b/src/test/resources/test-data.json @@ -149,7 +149,7 @@ }, { "input": "2017-12-21T12:20:45.9b7Z", - "error": "Invalid character starting at position 21: 2017-12-21T12:20:45.9b7Z", + "error": "Unexpected character b at position 22: 2017-12-21T12:20:45.9b7Z", "error_index": 21 }, {