Skip to content

Commit

Permalink
Reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Haraldsen committed Jan 25, 2024
1 parent 03fe2ab commit 89a7b8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/ethlo/time/internal/ErrorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/ethlo/time/internal/EthloITU.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -310,15 +312,15 @@ 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)
{
if (raw)
{
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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand Down

0 comments on commit 89a7b8d

Please sign in to comment.