@Test(expected = ParseException.class) public void testParse00() throws ParseException { ISO8601TimeZone.fromString(""); }
public static ISO8601TimeZone fromString(String timezoneString) throws ParseException { if (timezoneString == null) { throw new NullPointerException(); } if (timezoneString.length() == 0) { throw new ParseException("zero length string for time zone", 0); } int startPos = ParseUtils.nextNonWhite(timezoneString, 0); int offsetMinutes = 0; int signPart = 1; switch(timezoneString.charAt(startPos)) { case 'Z': offsetMinutes = 0; startPos++; break; case '-': signPart = -1; case '+': startPos++; int hourPart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (hourPart < 0 || hourPart > 24) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; if (startPos >= timezoneString.length() || timezoneString.charAt(startPos) != ':') { throw new ParseException("Invalid time string", startPos); } startPos++; int minutePart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (minutePart < 0 || minutePart >= 60) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; offsetMinutes = signPart*(hourPart*60 + minutePart); break; default: throw new ParseException("Invalid timezone", startPos); } return new ISO8601TimeZone(offsetMinutes); }
ISO8601TimeZone implements Comparable<ISO8601TimeZone>, SemanticString { public static ISO8601TimeZone fromString(String timezoneString) throws ParseException { if (timezoneString == null) { throw new NullPointerException(); } if (timezoneString.length() == 0) { throw new ParseException("zero length string for time zone", 0); } int startPos = ParseUtils.nextNonWhite(timezoneString, 0); int offsetMinutes = 0; int signPart = 1; switch(timezoneString.charAt(startPos)) { case 'Z': offsetMinutes = 0; startPos++; break; case '-': signPart = -1; case '+': startPos++; int hourPart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (hourPart < 0 || hourPart > 24) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; if (startPos >= timezoneString.length() || timezoneString.charAt(startPos) != ':') { throw new ParseException("Invalid time string", startPos); } startPos++; int minutePart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (minutePart < 0 || minutePart >= 60) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; offsetMinutes = signPart*(hourPart*60 + minutePart); break; default: throw new ParseException("Invalid timezone", startPos); } return new ISO8601TimeZone(offsetMinutes); } }
ISO8601TimeZone implements Comparable<ISO8601TimeZone>, SemanticString { public static ISO8601TimeZone fromString(String timezoneString) throws ParseException { if (timezoneString == null) { throw new NullPointerException(); } if (timezoneString.length() == 0) { throw new ParseException("zero length string for time zone", 0); } int startPos = ParseUtils.nextNonWhite(timezoneString, 0); int offsetMinutes = 0; int signPart = 1; switch(timezoneString.charAt(startPos)) { case 'Z': offsetMinutes = 0; startPos++; break; case '-': signPart = -1; case '+': startPos++; int hourPart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (hourPart < 0 || hourPart > 24) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; if (startPos >= timezoneString.length() || timezoneString.charAt(startPos) != ':') { throw new ParseException("Invalid time string", startPos); } startPos++; int minutePart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (minutePart < 0 || minutePart >= 60) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; offsetMinutes = signPart*(hourPart*60 + minutePart); break; default: throw new ParseException("Invalid timezone", startPos); } return new ISO8601TimeZone(offsetMinutes); } ISO8601TimeZone(int tzOffsetMinutesIn); }
ISO8601TimeZone implements Comparable<ISO8601TimeZone>, SemanticString { public static ISO8601TimeZone fromString(String timezoneString) throws ParseException { if (timezoneString == null) { throw new NullPointerException(); } if (timezoneString.length() == 0) { throw new ParseException("zero length string for time zone", 0); } int startPos = ParseUtils.nextNonWhite(timezoneString, 0); int offsetMinutes = 0; int signPart = 1; switch(timezoneString.charAt(startPos)) { case 'Z': offsetMinutes = 0; startPos++; break; case '-': signPart = -1; case '+': startPos++; int hourPart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (hourPart < 0 || hourPart > 24) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; if (startPos >= timezoneString.length() || timezoneString.charAt(startPos) != ':') { throw new ParseException("Invalid time string", startPos); } startPos++; int minutePart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (minutePart < 0 || minutePart >= 60) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; offsetMinutes = signPart*(hourPart*60 + minutePart); break; default: throw new ParseException("Invalid timezone", startPos); } return new ISO8601TimeZone(offsetMinutes); } ISO8601TimeZone(int tzOffsetMinutesIn); static ISO8601TimeZone fromString(String timezoneString); int getTzOffsetMinutes(); String getTimeZoneString(); @Override String stringValue(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(ISO8601TimeZone o); }
ISO8601TimeZone implements Comparable<ISO8601TimeZone>, SemanticString { public static ISO8601TimeZone fromString(String timezoneString) throws ParseException { if (timezoneString == null) { throw new NullPointerException(); } if (timezoneString.length() == 0) { throw new ParseException("zero length string for time zone", 0); } int startPos = ParseUtils.nextNonWhite(timezoneString, 0); int offsetMinutes = 0; int signPart = 1; switch(timezoneString.charAt(startPos)) { case 'Z': offsetMinutes = 0; startPos++; break; case '-': signPart = -1; case '+': startPos++; int hourPart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (hourPart < 0 || hourPart > 24) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; if (startPos >= timezoneString.length() || timezoneString.charAt(startPos) != ':') { throw new ParseException("Invalid time string", startPos); } startPos++; int minutePart = ParseUtils.getTwoDigitValue(timezoneString, startPos); if (minutePart < 0 || minutePart >= 60) { throw new ParseException("Invalid timezone", startPos); } startPos += 2; offsetMinutes = signPart*(hourPart*60 + minutePart); break; default: throw new ParseException("Invalid timezone", startPos); } return new ISO8601TimeZone(offsetMinutes); } ISO8601TimeZone(int tzOffsetMinutesIn); static ISO8601TimeZone fromString(String timezoneString); int getTzOffsetMinutes(); String getTimeZoneString(); @Override String stringValue(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(ISO8601TimeZone o); static final ISO8601TimeZone TIMEZONE_GMT; }