Skip to content

Commit

Permalink
fix off-by-one-error
Browse files Browse the repository at this point in the history
  • Loading branch information
x0b committed Jun 30, 2018
1 parent 6e17155 commit 46cf185
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private synchronized static Date parseOffset(Date date, String timeString) throw
private static char getTimezoneStyle(String timeString, char... styleIds){
for (char c: styleIds) {
int lastIndex = timeString.lastIndexOf(c);
if(lastIndex != -1 && lastIndex > 19){
if(lastIndex != -1 && lastIndex >= 19){
return c;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Calendar;
Expand Down Expand Up @@ -143,6 +145,13 @@ public void parseTimeZoneUnsupportedFail() throws ParseException {
Rfc3339.parseTimezone("1996-12-19T16:39:57.203GMT0800");
}

@Test
public void testInternalTzStyle() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Method getTzStyle = Rfc3339.class.getDeclaredMethod("getTimezoneStyle", String.class, char[].class);
getTzStyle.setAccessible(true);
getTzStyle.invoke(null, "1996-12-19T16:39:57+01:30", new char[]{'+', '-', 'Z'});
}

@Test
public void parseCalendar() throws ParseException {
String timeString = "1996-12-19T16:39:57.123+01:30";
Expand Down

1 comment on commit 46cf185

@x0b
Copy link
Owner Author

@x0b x0b commented on 46cf185 Jun 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #2

Please sign in to comment.